在Vim 中自动进行GNU 编程风格的缩进

来源:互联网 发布:08cms产品库报价系统 编辑:程序博客网 时间:2024/06/05 15:40
2014/05/11:修改了cinoptions,消除了函数名称后直接跟括号(无横向空白)时缩进错误的bug。

2014/05/26:进一步修改使之更加贴近GNU 编程风格。

2014/05/26:修正了cinoptios,消除了函数体括号被强制缩进的错误。

" ==========================" GNU 缩进风格" ==========================" 如果不喜欢GNU 缩进风格" 请注释掉函数后的au 一行" ==========================function! GnuIndent ()  let b:did_ftplugin = 1  setlocal cindent  setlocal shiftwidth=2 tabstop=2 textwidth=78 softtabstop=2  setlocal cinoptions=>2s,e-s,n-s,{1s,^-s,Ls,:s,=s,g0,+.5s,p2s,t0,(0  setlocal formatoptions-=t formatoptions+=croql  setlocal comments=sO:*\ -,mO:\ \ \ ,exO:*/,s1:/*,mb:\ ,ex:*/  set cpoptions-=C  set expandtab smarttab autoindent smartindentendfunctionau FileType c,cpp,h,hh call GnuIndent ()

确定你的Vim 开启了文件检测:

filetype plugin indent on

确定你的Vim 没有手动默认指定filetype:

" 下面指定默认编辑文件类型的语句" 会导致GnuIndent 函数无法正常工作set filetype=perl

现在你的Vim 应该就能在写C/C++ 代码的时候自动进行GNU 编程风格的缩进了。

0 0