Annoying vim (un)indent rules


Question

When editing PHP code (I'm not sure if it's specific to that language) and I create a new line in the middle of comma-separated lists that span multiple lines, the indent rules always unindent the line I'm leaving. Here's a video of it. This happens in arrays, function argument lists, etc.

Is there anything I can do to stop this from happening, or any quicker methods of fixing the error than moving up, re-indenting it, moving down, re-indenting (since it gets cleared when you leave the line), and continuing?

.vimrc

1
12
11/25/2008 9:43:09 PM

Your indenting is controlled by the PHP indent script ("filetype indent on" in your .vimrc). I use these options for my PHP indenting, which you put in ~/.vim/after/ftplugin:

setlocal autoindent
setlocal cindent
setlocal cinwords=if,else,elseif,do,while,foreach,for,case,default,function,class,interface,abstract,private,public,protected,final
setlocal cinkeys=0{,0},0),!^F,o,O,e

setlocal nosmartindent " don't use smart indent option

There's more on this topic on the vim wiki page for source indenting.

3
7/19/2012 10:16:26 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon