Take the 2-minute tour ×

Not sure which stack exchange group this question goes so please move to the correct one if this is the wrong one.

What's happening is if I highlight something with tabs/indents from one window/browser and want to paste it into vi, the formatting gets messed up.

For example, I have the following in another window that I want to copy:

   "date_created" : "2013-06-06 21:12:31",
   "netdriver_duplex" : "Full",
   "mac_address" : "FA:16:3E:17:CC:E1",
   "interfaces" : "eth0,sit0",
   "processors" : null

After I highlight it and paste it in vi, I get the following:

      "netdriver_duplex" : "Full",
            "interfaces" : "eth0,sit0",
               "processors" : null

Someone told me auto-indent is messing me up and to run

ESC-> :set noai
Copy/Paste stuff
ESC-> :set ai

but this gets tiring after a while. Is there a workaround when pasting tabbed lines in vi with autoindent set to on or do I have to turn off auto-indent, paste, turn ai back on every time?

Thanks in advance for your help.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Are you using i<Ctrl>V to paste? Try using "+p instead.

I find this problem whenever I try to use the operating system's copy-n-paste method, versus using vim's. If you try to paste while you're in insert mode, vim thinks that you typed it in really fast instead of pasting. It doesn't know how to keep the formatting in this case.

However, if you exit insert mode Esc, and then paste from the + register (which is aliased to the operating system buffer), it works.

Thus, "+p.

Note that on X-11, you can also use the * register to access the X11 selection. Also, either of these only work if vim has been compiled with X11 integration support. Works for vim as well as gvim, though.

share|improve this answer
yes, I'm using <ESC>i<Ctrl>V. I just tried <ESC>"+p but all it printed was :s in my vi window. =( <br/> I don't know if it makes a difference but I forgot to mention this is on a Mac. I just click on terminal and a unix terminal window opens up. From here, I run vi. <br/> would this be an instance where I have to use the * register that you mention above? How would I use it b/c I'm blinding using <ESC>"*p and that didn't work =) <br/> Thanks again for your help. –  Classified Jun 18 '13 at 21:56
Everything I know about is is from :help quoteplus and :help quotestar. It works for me on Linux, but I know nothing of Mac. –  jpaugh Jun 18 '13 at 22:02
If you can't find a good solution here, the people over at vim_use@googlegroups.com are smart as a tack. Some of them are even vim developers. –  jpaugh Jun 18 '13 at 22:04
thx for your help and the tips. –  Classified Jun 20 '13 at 18:20

Your Answer


