如何在extern"C"{line中设置vim not auto indent

Dra*_*laW 7 vim

在我们的项目中,将有

#ifdef __cplusplus
extern "C" {
#endif
    int foobar();  // <-- vim auto indent it
Run Code Online (Sandbox Code Playgroud)

如何设置vimrc或c-support让vim不自动缩进只是为了extern"C"旁边使用Marco替换extern"C"{?

lol*_*llo 0

vim 中的缩进通过 'cinoptions' 配置。但它不支持“extern C”。请参阅类似问题的答案

function! IndentNamespace()
    let l:cline_num = line('.')
    let l:pline_num = prevnonblank(l:cline_num - 1)
    let l:pline = getline(l:pline_num)
    let l:retv = cindent('.')
    while l:pline =~# '\(^\s*{\s*\|^\s*//\|^\s*/\*\|\*/\s*$\)'
        let l:pline_num = prevnonblank(l:pline_num - 1)
        let l:pline = getline(l:pline_num)
    endwhile
    if l:pline =~# '^\s*extern "C".*'
        let l:retv = 0
    endif
    return l:retv
endfunction

setlocal indentexpr=IndentNamespace()
Run Code Online (Sandbox Code Playgroud)

将其另存为 ~/.vim/indent/cpp.vim