简体   繁体   English

.php的Vim怪异缩进

[英]Vim weird indentation for .php

I want to like this behavior of vim indentation. 我想喜欢vim缩进的这种行为。

public function foo()
{
    _ <= cursor position
}

But, it becomes way... 但是,变成了...

public function foo()
{
    _
    } 

My .vimrc is 我的.vimrc是

filetype plugin indent on

set expandtab
set tabstop=4
set softtabstop=0
set shiftwidth=4
set autoindent
set smartindent

autocmd FileType php setlocal sw=4 sts=4 ts=4 et
au BufRead,BufNewFile,BufReadPre *.php setl ft=php

inoremap {<Enter> {}<Left><CR><ESC><S-o>
inoremap [<Enter> []<Left><CR><ESC><S-o>
inoremap (<Enter> ()<Left><CR><ESC><S-o>

And whole is here . 整个就在这里

Any ideas on what this might be? 关于这可能是什么想法?

It behaves like this because if you cut the line with <Left><CR> , vim will not take the end of the line ( "}" in your case) in consideration for indenting. 之所以这样,是因为如果您用<Left><CR>剪切行,vim将不会考虑行的结尾(在您的情况下为"}" )以考虑缩进。

Try this mapping instead: 请尝试以下映射:

inoremap {<Enter> {<cr>}<esc>O

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM