Vim Tip: Copy and paste into the editor ...

Fact #1

Copy and Paste is a damned implementation pattern in programming. But it is also one of the best ways to use code written (on the web, e.g.) as a starting point.

Fact #2

Vim is one of the best text editors.

Now if we assume you vim most of the times you play with text files, you would be annoyed if copying text from somewhere on the web and pasting it into a vim buffer would mess up the alignment. For example, text that shows up like this on the web page:

  class Product
    def initialize( code, name, desc, cost )
      @code = code
      @name = name
      @desc = desc
      @cost = cost
shows up like this when "Ctrl+C, Ctrl+v"ed in your vim session:
  class Product
              def initialize( code, name, desc, cost )
                            @code = code
                                  @name = name
                                        @desc = desc
                                              @cost = cost
Well, no more. Just do :set paste or in your .vimrc, set paste which puts vim in the so-called paste mode and you will see that sanity returns. I appreciate (Google, and) help from this vim-group entry.
Comments:

<b>Update: </b>
Note that in the paste mode none of the mappings work and then you need to use :set nopaste. So, paste is not to be used in your .vimrc.

Posted by Kedar Mhaswade on April 27, 2009 at 12:42 PM PDT #

IMO, the fact that even something as simple as copy&paste requires such a horrible workaround shows how broken some parts of Unix are (although I don't know what to blame in this case.)

Hopefully gvim handles clipboard better.

Posted by Kohsuke Kawaguchi on April 28, 2009 at 02:45 PM PDT #

You can change the mouse mode with set mouse=..., but I prefer to do set paste.

Posted by Eric on June 02, 2009 at 02:47 AM PDT #

Thanks for this - didn't realize there was a solution to this annoying problem until I looked it up :)

Posted by Matt on December 16, 2010 at 07:46 PM PST #

Post a Comment:
Comments are closed for this entry.
About

Welcome to my blog where mostly my work related thoughts are expressed.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today