是否可以在 VIM 中折叠 C 预处理器。例如:
#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
(或 Windows 上的等效 vimfiles 路径):" 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
关于vim - 在 VIM 中折叠 C 预处理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2407920/