简体   繁体   English

如何激活vim折叠标记?

[英]how to activate vim folding markers?

I have inherited some c++ code with vim-based folding markers like this: 我继承了一些基于vim的折叠标记的c ++代码,如下所示:

// CONSTRUCTORS/DESTRUCTORS /*{{{*/
Foo::Foo()
{
}
Foo::~Foo()
{
}
/*}}}*/

What do I need to put into my .vimrc to enable folding toggles like zm and space-bar? 我需要在.vimrc中添加什么才能启用zm和space-bar等折叠切换?

With my current settings, when I hit space bar inside or zm, vim does nothing. 使用我当前的设置,当我点击空格键或zm时,vim什么都不做。

The default keybindings for folding are za or zm (though zm I think only closes folds, while za toggles them), so you should add the following lines to your .vimrc: 折叠的默认键绑定是zazm (虽然zm我认为只关闭折叠,而za切换它们),所以你应该将以下行添加到你的.vimrc:

set foldmethod=marker to enable folding triggered by markers (the {{{ things in your code) set foldmethod=marker以启用由标记触发的折叠( {{{代码中的内容)

nnoremap <space> za to enable space to trigger the fold in normal mode. nnoremap <space> za使space能够在正常模式下触发折叠。

But! 但! if you're not sure if you want to enable folding in other files, you could use autocmd s, like so: 如果您不确定是否要在其他文件中启用折叠,可以使用autocmd ,如下所示:

autocmd FileType vim,c++,txt setlocal foldmethod=marker and that will ensure that folding only works in vim, c++, and text files. autocmd FileType vim,c++,txt setlocal foldmethod=marker ,这将确保折叠仅适用于vim,c ++和文本文件。

By the way, what you've posted is only one kind of folding mentioned by vim guru Steve Losh in this article . 顺便说一句,你发布的内容只是vim大师Steve Losh在本文中提到的一种折叠。 Read it to learn more about folding. 阅读它以了解有关折叠的更多信息。 It's super cool. 这太酷了。

OK, after googling around for a bit, I found this which seems to work: 好吧,谷歌搜索了一下后,我发现这似乎有效:

set foldmethod=marker                                                                 |~
nnoremap <space> za

If you only have a few files or if you just wish to control option(s) on a per file basis you may want to use modeline . 如果只有几个文件,或者如果你只是想控制对每个文件的基础选项(S),你可能想使用modeline My intro to folding came when I download a z-shell script and when I opened it, was surprised to find everything folded. 当我下载一个z-shell脚本时,我的折叠介绍来了,当我打开它时,惊讶地发现所有东西都折叠了。 Found something like this at the end of the file: 在文件末尾找到类似的东西:

# vim:ts=4:sw=4:ai:foldmethod=marker:foldlevel=0:

Change commenting to match your code type, and insure there is a space before the word vim . 更改注释以匹配您的代码类型,并确保在vim之前有一个空格。 As always a good place to start: :help modeline and :help folding . 一如既往的好地方:help modeline:help folding You may have to add set modeline to your .vimrc file if modeline was not set at build time. 您可能需要增加set modeline ,如果你的.vimrc文件modeline没有设置在构建时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM