题
它是可能的折C预处理器在VIM。例如:
#if defined(DEBUG)
//some block of code
myfunction();
#endif
我想把它折叠,所以,它将变成:
+-- 4 lines: #if defined(DEBUG)---
解决方案
这是不平凡由于限制Vim强调发动机:它不突出重叠的区域非常好。你有两个选择,因为我看到它:
使用的语法突出和更有关的
contains=
选项,直到它对你的作品(将取决于一些插件可能):syn region cMyFold start="#if" end="#end" transparent fold contains=ALL " OR syn region cMyFold start="#if" end="#end" transparent fold contains=ALLBUT,cCppSkip " OR something else along those lines " Use syntax folding set foldmethod=syntax
这可能会采取很多乱搞,你可能永远不会得到它的工作令人满意。把这个放在
vimfiles/after/syntax/c.vim
或~/.vim/after/syntax/c.vim
.使用的折的标志。这将工作,但你不可以折叠时在括号或其他任何东西,你可能会喜欢的。把这个放在
~/.vim/after/ftplugin/c.vim
(或相当于vimfiles路上Windows):" This function customises what is displayed on the folded line: set foldtext=MyFoldText() function! MyFoldText() let line = getline(v:foldstart) let linecount = v:foldend + 1 - v:foldstart let plural = "" if linecount != 1 let plural = "s" endif let foldtext = printf(" +%s %d line%s: %s", v:folddashes, linecount, plural, line) return foldtext endfunction " This is the line that works the magic set foldmarker=#if,#endif set foldmethod=marker
其他提示
我已经能够通过添加这些行到我的c.vim语法文件得到它的工作我喜欢的:
syn match cPreConditMatch display "^\s*\zs\(%:\|#\)\s*\(else\|endif\)\>"
+syn region cCppIfAnyWrapper start="^\(%:\|#\)\s*\(if\|ifdef\|ifndef\|elif\)\s\+.*\s*\($\|//\|/\*\|&\)" end="^\s*\(%:\|#\)\s*endif\>" contains=TOP,cCppInIfAny,cCppInElseAny fold
+syn region cCppInIfAny start="^\(%:\|#\)\s*\(if\|ifdef\|ifndef\|elif\)\s\+.*\s*\($\|//\|/\*\|&\)" end="^\s*\(%:\|#\)\s*\(else\s*\|elif\s\+\|endif\)\>"me=s-1 containedin=cCppIfAnyWrapper contains=TOP
+syn region cCppInElseAny start="^\s*\(%:\|#\)\s*\(else\|elif\)" end="^\s*\(%:\|#\)\s*endif\>"me=s-1 containedin=cCppIfAnyWrapper contains=TOP
if !exists("c_no_if0")
不隶属于 StackOverflow