如何设置打开文件时默认展开?

发布于 2024-12-18 12:55:37 字数 156 浏览 3 评论 0原文

在我的 .vimrc 中,我放置了 set Foldmethod=syntax 来启用方法折叠等。但是,我不喜欢每次打开文件时的默认设置整个东西都折叠起来了。有没有办法启用 foldmethod,但打开文件时文件会展开?

In my .vimrc I've put set foldmethod=syntax to enable folding of methods etc. However, I don't like the default that everytime I open a file, the whole thing is folded. Is there a way to enable foldmethod, yet have files unfolded when I open them?

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

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

发布评论

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

评论(9

多孤肩上扛 2024-12-25 12:55:37
set foldlevel=99

无论使用何种折叠方法,都应打开所有折叠。 foldlevel=0 全部折叠,foldlevel=1 仅部分折叠,...数字越大,折叠越少。

set foldlevel=99

should open all folds, regardless of method used for folding. With foldlevel=0 all folded, foldlevel=1 only somes, ... higher numbers will close fewer folds.

长梦不多时 2024-12-25 12:55:37

您可以将其放入 .vimrc 中:
au BufRead * normal zR

它声明一个自动命令 (au),当读取缓冲区 (BufRead) 时触发,匹配所有文件 (< code>*)并在正常模式下执行zR(打开所有折叠)命令。

You can put this in your .vimrc:
au BufRead * normal zR

It declares an automatic command (au), triggered when a buffer is read (BufRead), matching all files (*) and executes the zR (opens all folds) command in normal mode.

奈何桥上唱咆哮 2024-12-25 12:55:37
set nofoldenable

将其添加到 .vimrc 中将在您打开文件时暂时禁用折叠,但仍然可以使用 zc 恢复折叠

set nofoldenable

Adding this to your .vimrc will temporarily disable folding when you open the file, but folds can still be restored with zc

阳光下的泡沫是彩色的 2024-12-25 12:55:37

.vimrc 中为 BufWinEnter 添加一个 autocmd 以自动打开所有折叠,如下所示:

autocmd BufWinEnter * silent! :%foldopen!

告诉 vim 在打开后执行 silent :%foldopen! BunWinEnter 事件(参见 :h BufWinEnter)。 silent %foldopen! 将执行 foldopen 由于 % 在整个缓冲区上,并且由于 ! 将递归地打开所有折叠。任何最终的错误消息都将被 silent 抑制。 (如果缓冲区实际上尚未包含任何折叠,您可能会收到类似 E490: No Fold found 的错误消息)

注意:您可以使用 BufRead 而不是 BufWinEnter 但如果文件具有启用折叠的模型行,则会覆盖此 autocmd。我的意思是 BufRead autocmd 在处理模型行之前运行,而 BufWinEnter 将在处理之后运行它们。我发现后者更有用

In .vimrc add an autocmd for BufWinEnter to open all folds automatically like this:

autocmd BufWinEnter * silent! :%foldopen!

That tell vim to execute the silent :%foldopen! after opening BunWinEnter event (see :h BufWinEnter). The silent %foldopen! will execute foldopen on the whole buffer thanks to the % and will open all folds recursively because of the !. Any eventual error message will be suppressed by silent. (You could get error messages like E490: No fold found if the buffer actually didn't contain any fold yet)

Note: You could use BufRead instead of BufWinEnter but then if the file has a modeline that enables the folding that will override this autocmd. I mean BufRead autocmds run before the modeline is processed and BufWinEnter will run them after. I find the later to be more useful

蓝海似她心 2024-12-25 12:55:37

您可以添加

set foldlevelstart=99

到 .vimrc 文件,它将开始编辑所有打开的折叠的任何新文件。

You can add

set foldlevelstart=99

to your .vimrc file, and it will start editing any new file with all folds open.

够钟 2024-12-25 12:55:37

如果您想要一种方法让它在打开后立即展开,您可以使用 set Foldlevelstart=99 正如许多答案所解释的那样。

但是,如果您只想查看它们展开的情况,只需按 zi 即可展开所有内容。另外,zi 会将它们关闭。

If you want a way to have it display unfolded as soon as it is opened, you can use set foldlevelstart=99 as a lot of answers explained.

But, if you just want to see them unfolded, you can just press zi and it will unfold everything. Another, zi will close them back.

笔落惊风雨 2024-12-25 12:55:37

您可以将其映射到按键以启用它。
例如,

nmap ,f :set foldmethod=syntax<CR>

然后在正常模式下按“,f”组合键

You could map it to keys to enable it.
For example,

nmap ,f :set foldmethod=syntax<CR>

Then while in normal mode hit the ",f" key combination

时光礼记 2024-12-25 12:55:37

当您将 set nofoldenable 放入 .vimrc 文件中时,您可以打开展开的文件。

You can open unfolded file when you put set nofoldenable into your .vimrc file.

ㄟ。诗瑗 2024-12-25 12:55:37

autocmd BufReadPost * 无声! :%foldopen!

这对我来说效果最好。缓冲区打开后,所有折叠都会打开。这将使他们达到正确的水平。

set Foldenable 方法不好,因为如果我选择关闭一个折叠级别,它会再次启用折叠,并将所有内容折叠到 0 级别,而不是仅在我激活的级别上下降一级。

autocmd BufReadPost * silent! :%foldopen!

This worked best for me. After a buffer gets opened all folds are opened. This opens them to the correct level.

The set foldenable method was not good, because if I choose to close one fold level, it enabled folding again, and folded every thing to 0 level, instead of just going down one level on the one I activated.

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