gpt4 book ai didi

vim - 在 VIM 中折叠 C 预处理器

转载 作者:行者123 更新时间:2023-12-04 16:02:43 27 4
gpt4 key购买 nike

是否可以在 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/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com