Have you ever tried to cut and paste text into vi or vim through a terminal, only to find the formatting completely screwed up? Yeah, me too…  I finally came across an answer to this pesky problem and it’s so simple, I’m surprised it wasn’t easier to find. The next time you want to paste text with tabs into vi or vim, try the following:

Make sure you’re in command mode by pressing escape, then enter

:set paste

Don’t forget the colon at the beginning of the command. Now, when you enter edit mode, you’ll see

-- INSERT (paste) --

at the bottom of the screen. Also, anything you paste into the terminal will retain it’s formatting. Pretty simple, eh? To exit this mode, just type

:set nopaste

Once again, make sure you are in command mode before you type this and don’t forget the leading colon. Hopefully, this will save someone else the hassle of digging around for hours trying to find this simple fix…