在我的〜/ .vimrc中,我具有以下缩进设置:
" If available, load indenting file for specific file type.
filetype indent on
" Does nothing more than copy the indnetation from the previous line,
" when starting a new line. autoindent does not interfere with other
" indentation settings
set autoindent
" Spaces are better than tab character
set smarttab expandtab
set shiftwidth=4
set tabstop = 4
Run Code Online (Sandbox Code Playgroud)
在大多数情况下,这可以正常工作。但是有一件事让我很烦。
当我在.cpp文件中有一个switch / case语句时,案例会自动缩进,例如
switch (x) {
case A:
// ...
Run Code Online (Sandbox Code Playgroud)
虽然我真正想要的是:
swith (x) {
case A:
// ...
Run Code Online (Sandbox Code Playgroud)
有什么办法可以改变这种行为?(注意:我的文件~/.vim/syntax
夹中没有特定的.cpp语法文件)。
你要:
set cinoptions+=:0
Run Code Online (Sandbox Code Playgroud)
这增加:0
了cindent
设置,该设置表示要以零字符缩进大小写标签。
要使其仅适用于C和C ++文件,可以使用:
au FileType c,cpp setl cindent cinoptions+=:0
Run Code Online (Sandbox Code Playgroud)
有关:help cinoptions-values
其他设置,请参见。
我cinoptions=:0,g0
这样使用public:
,protected:
并且private:
访问说明符也不缩进。