Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Annoying vim (un)indent rules

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

like image 665
Alex Suraci Avatar asked Nov 24 '08 03:11

Alex Suraci


2 Answers

Try :set indentexpr="" and see if that helps. See :help filetype-indent-off for the section that deals with filetype plugins (which is probably where this indentexpr is coming from).

like image 169
Greg Hewgill Avatar answered Oct 14 '22 17:10

Greg Hewgill


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.

like image 45
too much php Avatar answered Oct 14 '22 16:10

too much php