Vim中避免缩进C++ Namespace

Vim的cinoptions不支持定制C++的namespace缩进。不过,可以重写indent文件,把下面这个文件放到vimfiles/indent目录,即可。
cpp.vim如下:
[code]
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
" Set the function to do the work.
setlocal indentexpr=GetCppIndent()
" Only define the function once.
if exists("*GetCppIndent")
finish
endif
function GetCppIndent()
let indent = cindent(v:lnum)
if v:lnum < 2
return indent
endif
" Don't indent namespace block.
let prev = v:lnum - 1
let pline = getline(prev)
if pline =~ '^\s*namespace\s\+\a\+\s*{\s*$'
let indent = indent - &sw
elseif pline =~ '^\s*{\s*$'
if getline(prev - 1) =~ '^\s*namespace\s\+\a\+\s*$'
let indent = indent - &sw
endif
endif
return indent
endfunction
[/code]

用VC的同学就比较悲催了:http://blog.csdn.net/ganxinjiang/archive/2010/09/13/5880541.aspx

发表评论 | Trackback
2011年12月31日 | 归档于 未分类
标签:
本文目前尚无任何评论.

发表评论

XHTML: 您可以使用这些标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>