Annoying vim (un)indent rules

一个人想着一个人 提交于 2019-12-05 00:30:17

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

too much php

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.

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

Try this:

:let g:PHP_default_indenting=1

See :h php-indent.

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

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

you probably want to look at indentkeys

eg the default these days is:

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

Find your php.vim indent file. e.g. /usr/share/vim/vim73/indent/php.vim

Then look for these lines:

elseif lastline =~ '^\s*?>.*<?\%(php\)\=\s*$'
    let lnum = lnum - 1

And comment them out by prepending quotation marks, like this:

"elseif lastline =~ '^\s*?>.*<?\%(php\)\=\s*$'
"    let lnum = lnum - 1

That'll fix it! No more de-indenting on opening PHP tags <?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!