tags:

views:

1468

answers:

3

I want to paste something I have cut from my desktop into a file open in Vi.

But if I paste the tabs embed on top of each other across the page.

I think it is some sort of visual mode change but can't find the command.

A: 

If you are using VIM, you can use "*p (i.e. double quotes, asterisk, letter p).

JayG
+19  A: 

If you're using plain vi:

You probably have autoindent on. To turn it off while pasting:

<Esc> :set noai

<paste all you want>

<Esc> :set ai

I have in my .exrc the following shortcuts:

map ^P :set noai^M
map ^N :set ai^M

Note that these have to be the actual control characters - insert them using Ctrl-V Ctrl-P and so on.

If you're using vim:

Use the paste option. In addition to disabling autoindent it will also set other options such as textwidth and wrapmargin to paste-friendly defaults:

<Esc> :set paste

<paste all you want>

<Esc> :set nopaste

You can also set a key to toggle the paste mode. My .vimrc has the following line:

set pastetoggle=<C-P> " Ctrl-P toggles paste mode
Antti Sykäri
A: 

I found that if I copy tabbed lines first into a text editor and then recopy them from there to vim, then the tabs are correct.

Edward Tanguay