在编辑 .cpp 文件时删除 switch 语句后的额外缩进
Remove extra indent after switch statement, when editing a .cpp file
在我的 ~/.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
这在大多数情况下都可以正常工作。然而有一件事让我很烦恼。
当我在 .cpp 文件中有 switch / case 语句时,case 会自动缩进,例如
switch (x) {
case A:
// ...
而我真正想要的是:
swith (x) {
case A:
// ...
有什么办法可以改变这种行为吗? (注意:我的 ~/.vim/syntax
文件夹中没有特定的 .cpp 语法文件)。
你想要:
set cinoptions+=:0
将 :0
添加到 cindent
设置中,表示将大小写标签缩进零个字符。
要使其仅适用于 C 和 C++ 文件,您可以使用:
au FileType c,cpp setl cindent cinoptions+=:0
有关其他设置,请参阅 :help cinoptions-values
。
我使用 cinoptions=:0,g0
以便 public:
、protected:
和 private:
访问说明符也不会缩进。
在我的 ~/.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
这在大多数情况下都可以正常工作。然而有一件事让我很烦恼。
当我在 .cpp 文件中有 switch / case 语句时,case 会自动缩进,例如
switch (x) {
case A:
// ...
而我真正想要的是:
swith (x) {
case A:
// ...
有什么办法可以改变这种行为吗? (注意:我的 ~/.vim/syntax
文件夹中没有特定的 .cpp 语法文件)。
你想要:
set cinoptions+=:0
将 :0
添加到 cindent
设置中,表示将大小写标签缩进零个字符。
要使其仅适用于 C 和 C++ 文件,您可以使用:
au FileType c,cpp setl cindent cinoptions+=:0
有关其他设置,请参阅 :help cinoptions-values
。
我使用 cinoptions=:0,g0
以便 public:
、protected:
和 private:
访问说明符也不会缩进。