Getting paste AND autoindent to work correctly in vim?

Eeezee

Diamond Member
Jul 23, 2005
9,922
0
76
Right now, I can either have autoindent (great for coding) or pasting that works correctly (great for anything else... and sometimes coding). Right now, if I set autoindent, my paste gets this really aggressive indenting, so each following line has several additional indents than it would normally (so pasting 15 lines, the 15th line has some ludicrous amount of indented space before the text)

Has anyone figured out a workaround for this kind of issue? I love my autoindent and would love not having to turn it off just to get paste working (even if it's only a one-line command)
 

Cogman

Lifer
Sep 19, 2000
10,284
138
106
Try cindent, or smartindent I find they are usually somewhat better then autoindent.

another solution is something like if you do 15 lines like :15yy then you can back indent those 15 lines with :15<< or forward with :15>>
 

Eeezee

Diamond Member
Jul 23, 2005
9,922
0
76
Hmm, cindent and smartindent don't seem to be working, they don't automatically indent anything; they don't seem to preserve the previous line's indentation, and when I type something like
{
it doesn't indent the next new line, either (even if I indent the previous line myself), which is what I'd expect from something like cindent

Nothinman, 'set paste' doesn't fix this for me. Autoindent likes to aggressively indent when I paste something, even with the set paste option
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Try the following in your .vimrc -- I find this does the expected thing on most versions of vim...

" support for autocommands?
if has("autocmd")

" load indent files, to automatically do language-dependent indenting.
filetype plugin indent on

else

set autoindent " always set autoindenting on

endif