How to cut and paste tabbed lines with auto indent set to on in vi [duplicate]

Tag: unix , vi , auto-indent Author: yadiahan Date: 2013-06-02

This question already has an answer here:

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:

   "date_created" : "2013-06-06 21:12:31",
      "netdriver_duplex" : "Full",
         "mac_address" : "FA:16:3E:17:CC:E1",
            "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.

Other Answer1

You have to use, in normal mode

:set paste

Then you paste what you want. To comeback to your original setting, use, in normal mode

:set nopaste