vim中的自适应标签

R.D*_*.D. 8 vim indentation

我碰巧在代码中工作,其中一些模块使用制表符进行缩进,而其他模块则使用空格.许多文本编辑器(如Np ++)都具有某种自适应标签功能,如果前一行(或代码块)使用空格,则使用空格进行缩进,或者根据具体情况使用制表符.

我没有在这样的vim中看到任何东西.有没有这样的插件或设置?

Joh*_*aul 3

我更喜欢像下面的示例所示设置我的环境。我制定了用空格替换制表符的一般规则,并augroup在需要覆盖该规则时使用。Makefile 是一个很好的例子,说明您可能需要 TABS,而 cpp 文件则说明您可能需要空格。

" A tab produces a 4-space indentation
:set softtabstop=4
:set shiftwidth=4
:set expandtab
" replace tabs with spaces unless noted otherwise

" <snip>

augroup CPPprog
   au!
   "-----------------------------------
   " GENERAL SETTINGS
   "-----------------------------------
   au BufRead,BufNewFile,BufEnter             *.cpp,*.c,*.h,*.hpp   set nolisp
   au BufRead,BufNewFile,BufEnter             *.cpp,*.c,*.h,*.hpp   set filetype=cpp
   au FileType                                *                     set nocindent smartindent
   au FileType                                *.c,*.cpp             set cindent
   au BufRead,BufNewFile,BufEnter             *.cpp                 let g:qt_syntax=1
   " turn on qt syntax highlighting (a plugin)
   au BufNewFile,BufRead,BufEnter             *.c,*.h,*.cpp,*.hpp   let c_space_errors=1
   " trailing white space and spaces before a <Tab>

   " <snip>

augroup END

" <snip>

augroup filetype
  au! BufRead,BufNewFile,BufEnter *Makefile*,*makefile*,*.mk set filetype=make
augroup END
" In Makefiles, don't expand tabs to spaces, since we need the actual tabs
autocmd FileType make set noexpandtab
Run Code Online (Sandbox Code Playgroud)