如何在 VIM 中共享我的折叠?

发布于 2024-07-13 12:00:48 字数 317 浏览 7 评论 0原文

我正在做一个有 3 个人的项目。 我们需要在 Vim 中为每个成员提供相同的折叠。 我如何分享我的折叠?

[反馈]

我明白了一件重要的事情:Google 会忽略诸如 {{{ 之类的符号,因此请在 google 上搜索“VIM 三括号”以查找有关标记方法的帮助。 练习变得更加容易,因为您可以快速找到相关信息。

为了使用标记方法(Adam Bellaire 建议的),请注意您必须设置方法:

:set foldmethod=marker

感谢您的回答!

I am in a project with 3 people. We need to have the same folds in Vim for each member. How can I share my folds?

[Feedback]

I understood one important thing: Google ignores signs, such as {{{, so please google "VIM three braces" to find help about the marker-method. It becomes much easier to practise, as you can quickly find relevant information.

In order to use the the marker-method (suggested by Adam Bellaire), please note that you have to set the method:

:set foldmethod=marker

Thanks for your answers!

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

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

发布评论

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

评论(4

不即不离 2024-07-20 12:00:48

最简单的方法可能是仅使用折叠标记(例如 {{{1),确保在文件本身中包含 vim:fdm=marker 设置。 例如,下面是一个 shell 脚本,其中包含使用折叠标记的设置和两级折叠:

#/bin/sh
# vim:fdm=marker
echo This file contains fold markers.

#Top Level Fold     {{{1
echo This is a top-level fold.

#Second Level Fold  {{{2
echo This is a second-level fold.

在 vim 中打开此文件将显示前四行,然后是折叠,如果展开,将显示第二个折叠。 只需确保在注释语法和 vim:fdm=marker 行之间添加一个空格,否则 vim 将看不到它。 例如,在 C 中您可以使用:

// vim:fdm=marker

Probably the easiest way is to just use fold markers (e.g. {{{1), making sure to include the vim:fdm=marker setting in the file itself. For example, here's a shell script which contains both the setting to use fold markers and two levels of fold:

#/bin/sh
# vim:fdm=marker
echo This file contains fold markers.

#Top Level Fold     {{{1
echo This is a top-level fold.

#Second Level Fold  {{{2
echo This is a second-level fold.

Opening this file in vim will show the first four lines and then a fold, which if expanded will reveal the second fold. Just make sure to put a space between your comment syntax and the vim:fdm=marker line or vim won't see it. For example, in C you could use:

// vim:fdm=marker
沩ん囻菔务 2024-07-20 12:00:48

折叠文件?
好吧,相同的设置应该会导致相同的折叠。

Vim 可以通过多种方式折叠:手动、通过缩进、通过表达式、通过语法和通过标记(默认情况下,我相信是弯括号,其中 3 个)。

因此,如果您有相同的 vim 版本,并且他们没有更改语法和缩进文件,请让他们检查您的 vimrc 中的 Foldmethod 和 Foldmarker 选项,并将它们复制到他们的 vimrc 文件中。 应该可以做到这一点。

Folds in files ?
Well, same settings should result in same folds.

Vim can fold in several ways: manually, by indent, by expression, by syntax, and by markers (by default, I believe are curved brackets, 3 of them).

So if you have the same vim version, and they haven't changed their syntax and indent files, let them check out your vimrc for foldmethod and foldmarker options, and copy them to their vimrc files. That should do it.

任谁 2024-07-20 12:00:48

我以前没有与其他人共享过 VIM 折叠,但是如果您在同一台计算机上工作,也许您可​​以使用 VIM 会话,这将保存您当前的状态(包括折叠)。 在 VIM 中运行以下命令:

 mks! /path/to/session_file

然后你的朋友就可以加载会话文件了:

vim -s /path/to/session_file

I haven't shared VIM folds with someone before, but if you're working on the same machine perhaps you can use VIM sessions, which will save your current state (including folds). Run the following command in VIM:

 mks! /path/to/session_file

Then your friend can load up the session file:

vim -s /path/to/session_file
尐偏执 2024-07-20 12:00:48

我知道古老的历史,但这可能是从 09 年 vim 版本出现以来就出现的,而且由于我还没有足够的声誉来发表评论,所以我们开始吧。

好消息是,保存文件的视图也应该保存手动折叠,甚至嵌套折叠。

坏消息是我发现它在 vim 7.0 (RHEL 5.5) 下没有产生一致的结果。 这可能已在后续更新中得到修复,遗憾的是,我们不允许安装。

Ancient history, I know, but this may have appeared since the version of vim present in '09, and since I don't have an adequate reputation to comment yet, here we go.

The good news is that saving a view for the file should save manual folds as well, even nested folds.

The bad news is that I found it didn't produce consistent results under vim 7.0 (RHEL 5.5). This may have been fixed in a subsequent update that, sad to say, we aren't allowed to install.

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