Vim中避免缩进C++ Namespace
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