如何在 Vim 中通过外部文件控制折叠?

发布于 2024-07-17 04:03:51 字数 114 浏览 3 评论 0原文

我一直在寻找一种解决方案,将折叠标记和代码放入外部隐藏文件中。 这样你就可以得到永久的折叠而没有额外的折叠痕迹。

如何在 Vim 中通过外部文件控制折叠?

I have been searching a solution which puts the fold marks and codes to an external hidden file.
This way you could have permanent folds without extra fold signs.

How can you control folds by an external file in Vim?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

つ低調成傷 2024-07-24 04:03:52

这是一个非常普遍的问题。 vim 中的“外部文件”到底是什么? 毕竟,Vim 是“外部”文件的集合。 因此,如果我在 vim 文件中定义折叠首选项,这是“外部文件”解决方案吗?

例如,您可以链接定义折叠的正则表达式机制并从外部文件获取它们。

但我想,你的意思是,“我可以定义一个外部文件,这样我就可以通过项目自定义折叠,这样在我给他们我的文件后,每个使用 vim 的人都会有相同的折叠”? 是的,我想你可以通过从上面的方法推断来做到这一点。

但请记住,vim 有几种折叠方法:

  • 手动 - 手动定义折叠(这很好,但它会给代码留下大量大括号,但它是“可移植的”)
  • 缩进 - 缩进定义折叠
  • 表达式(我用它来定义折叠表达式)提到的)
  • 语法 - 由语法突出显示
  • 标记定义 - 你已经知道

......最后,这一切都将归结为你的 vimrc 中的这几个设置。

我的建议:不要更改 vim 的缩进、语法等文件。 通常,您甚至不需要更改这些(除非您使用 vim 不支持的语言,我对此表示怀疑)。 因此,在 vimrc 和 vimfiles 目录中定义您的设置和首选项,然后为您的同事提供他们需要的首选项(通常只是 vimrc 中的首选项)以具有相同的折叠行为。

That's a very general question. What is "an external file" in vim, really ? Vim is, after all, a collection of "external" files. So if I define my folding preferences in my vimfiles, is that "an external file" solution ?

You could link, for example, define regex mechanisms of folding and source them from an external file.

But I think, what you ment is, "can I define an external file, so I can have by project custom folding, so that everyone who uses vim after I give them my files, will have the same folding" ? Yes, I guess you could do that by extrapolating from the method above.

But remember, vim has several methods of folding:

  • manual - where you manually define folds (this is nice, but it leaves your code with lots of curly brackets, but it is "portable")
  • indenting - where indending defines folds
  • expression (which I mentioned)
  • syntax - defined by syntax highlighting
  • marker - you already know that

... in the end, it will all come down to those few settings in your vimrc.

My advice: DO NOT CHANGE vim's indenting, syntax, etc. files. Normally, you will not even need to change those (unless you're using a language vim has no support for, which I doubt). So, define your settings and preferences in your vimrc and vimfiles directory, and just give your coleagues preferences which they need (usually just those from vimrc) to have the same folding behaviour.

我是男神闪亮亮 2024-07-24 04:03:52

可以使 Vim 自动记住文件中的折叠

通过将这两行放入 ~/.vimrc au BufWinLeave ?* mkview
au BufWinEnter ?* 静默加载视图

Vim can be made to atuomatically remember folds in a file by putting these two lines in ~/.vimrc

au BufWinLeave ?* mkview
au BufWinEnter ?* silent loadview

烙印 2024-07-24 04:03:52

使用手动方法进行折叠。 这与上面暗示的 marker 不同。 使用 :mkview 保存折叠并使用 :loadview 重新加载它们。

Use manual method of making folds. This is not the same as marker as implied above. Use :mkview to save folds and :loadview to reload them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文