cut and paste source code to console

January 2nd, 2007 mysurface Posted in cat, Text Manipulation | Hits: 83409 | 16 Comments »

If your vim have auto indent enabled, you may facing this problem. Vim are too smart to help you indent copied source code, and the comment line will kill your pasting very much. I usually do copy and paste source code from ebook or web page to a file so that I can compile and run for test. In this case vim is not helping. I use cat instead.

Let say I copy a sample source code from the web, by typing the command line bellow:

cat > sample.c

I can now paste the source code and press Enter to insert a new line then ctrl+d after finish pasting.

Okay its done, now I can compile the sample source code.

16 Responses to “cut and paste source code to console”

  1. Do you have shortcut key for paste action in console?

    E.g. Copy some contents from a web page from Firefox and paste into vim in console.

  2. Paste to vim at console is dangerous, it may results something that out of your expectation. Use the example stated above is more promising.

    Shortcut for pasting to console is
    1. Mouse middle click
    2. keyboard Shift+Insert

  3. I think this will help for vim

    :set paste
  4. Great! that works!

  5. Really thanks for the keyboard shortcut! I know there must be a shortcut key for that.

    when using vim, in what case that we need to use the command:
    :set paste

    As I try, there is nothing different with/without that command. Could you illustrate an example that able to show the difference?

  6. But don’t set :set paste permanently in your .vimrc, as it disables imap, cmap, and abbreviations.

  7. correct, the best way is do it by toggle set paste like this
    :set paste!
    When you trigger the second time, the set paste will be disabled.

  8. hw 2 get d hours from 12:09:08 using cut command
    explain in brief
    i m new 2 linux……

  9. mythili:
    You are looking for cut command instead, this post talks about cut and paste into vim which is not what you want.
    Type cut at search text box, and the result will be this.

  10. btw, simply

    does often the same job.

  11. my paste function ;

    “fix pasting so you dont get the step down effect
    nnoremap <F5> :set invpaste paste?<Enter>
    imap <F5> <C-O><F5>
    set pastetoggle=<F5>

  12. adam: Not really understand how it works, but will look into it later, thanks.

  13. Sorry for the last comment …
    not what I wanted to show you (pasted the wrong text …)
    The following steps is what I use to copy/paste between multiples instances of VIM:

    Accessing the system clipboard
    From Vim Tips Wiki
    Jump to: navigation, search
    Tip 984 Previous Tip • Next Tip

    Created: September 4, 2005 Complexity: basic Author: JimD Minimum version: 6.0 Karma: 30/17 Imported from: Tip#984

    One of the traditional disconnects between vi and modern graphical environments has been using mouse-driven copy/paste between a terminal or command prompt window, and any other application (for example, a web browser).

    Vim has extended vi to allow use of the * register as a reference to the system clipboard. So we can use normal mode commands like: “*dd or 1G”*yG to copy things into the * register and “*p to paste text from it. We can also use this * register with the ex yank command, so :%y * will accomplish the same goal as gg”*yG (copy all text into the system clipboard so it can be pasted into an X or MS Windows application).

    The * register acts just like any of the normal (single letter) registers in vi except that it also refers to the system clipboard in X11 or MS Windows.

    I’ve also found that it’s much faster and more reliable than pasting a large body of text into Vim through an xterm. Normally I run Vim under the Linux screen utility and any more than one screen full of text is often corrupted, and large selections (>10KB) take several seconds of gnashing and flashing to finish pasting (almost always corrupted). By contrast, pasting 100KB text using “*p is very reliable and fast.

  14. Hey there! I realize this is somewhat offtopic but I had to ask. cadfceffdkdg

Leave a Reply