tags:

views:

1545

answers:

7

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  A: 

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).

Greg Hewgill
That didn't seem to change anything, which seems odd since I have that explicitly enabled in my .vimrc. My understanding is that with that off I'd lose the other "smart" indenting rules, though.
Alex Suraci
Tried `:set indentexpr="`, but now I have any auto-indenting at all.
Alex Suraci
Don't have any, rather.
Alex Suraci
I find that I work better with just the ":set autoindent" option turned on, rather than something else trying to format my code for me. There is also the "smartindent" option which might be halfway between autoindent and indentexpr.
Greg Hewgill
A: 

Using "o" in normal mode seems to avoid the issue. Hitting <esc>o from insert mode isn't optimal but it's better than the hard way (as described above).

Alex Suraci
A: 

Try this:

:let g:PHP_default_indenting=1

See :h php-indent.

Brian Carper
Didn't seem to change anything,
Alex Suraci
After you run the command, you have to :setf php again for it to take effect. Or else put the above in your ~/.vimrc and restart Vim.
Brian Carper
Ah, I see. That doesn't solve this problem, but that's still something I've been wanting to do. Thanks!
Alex Suraci
+1  A: 

Your indenting is controlled by the PHP indent script ("filetype indent on" in your .vimrc). I use these options for my PHP indenting:

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
too much php
A: 

You can also do

set cindkeys=-0#

For the # char. If you are having the same problem as I had with css declarations like

width: 100%

getting shifted left as well, you can add

set cindkeys-=:
A: 

I think cindent screws everything up and smartindent is usually what you want.

Try putting this in ~/.vim/filetype.vim:

au BufNewFile,BufRead *.html,*.css setlocal nocindent smartindent
a paid nerd
A: 

you probably want to look at indentkeys

eg the default these days is:

indentkeys=0{,0},:,0#,!^F,o,O,e,*,<>>,,end,: