如何让帮助窗口始终在同一位置打开?

发布于 2024-12-05 17:36:26 字数 362 浏览 0 评论 0原文

我这样做是为了在垂直窗口中打开帮助页面:

cabbrev help vert botright help

这样,可以,但有点令人不安,而且它也有点垃圾邮件我的 :history 。 我想让 Vim 不扩展它,只运行命令。因此,当我编写 :help topic 时,我希望它不展开,而是运行命令 :vert botright help topic 我尝试过

cabbrev <silent> help vert botright help

但它不起作用。

有可能做到吗?

I do this for opening help pages in vertical window:

cabbrev help vert botright help

this way, it is ok, but a bit disturbing, and it is spamming my :history a bit too.
I would like to get Vim to not expand this, just run the command. So when I write :help topic I want it to not expanded, but to run the command :vert botright help topic
I tried with

cabbrev <silent> help vert botright help

but it doesn't work.

Is it possible to do at all?

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

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

发布评论

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

评论(3

大海や 2024-12-12 17:36:26

我根据这封电子邮件找到了完美的解决方案:
http://vim.1045645.n5.nabble.com/Horizo​​ntal-layout-by-default-td1164876.html#a1164886
因此,如果您希望帮助窗口位于右侧,请执行以下操作:

autocmd FileType help :wincmd H

这会将 'help' 类型窗口立即置于右侧,就像 CTRL-WH 一样。请参阅 vim 中的 :h CTRL-W_H
如果您启用了隐藏选项,则使用 :q 关闭窗口不会卸载帮助窗口缓冲区,并且如果您想打开它,则存在一个小问题同样,由于某种原因,它不会触发 FileType 事件(为什么?),因此,如果您使用 :set hide 您需要:

autocmd FileType help set bufhidden=unload

获取帮助窗口卸载,无论如何,这是默认行为。

I found the perfect solution based on this e-mail:
http://vim.1045645.n5.nabble.com/Horizontal-layout-by-default-td1164876.html#a1164886
So if you want help windows on the right, do this:

autocmd FileType help :wincmd H

this puts the 'help' type windows immediately to the right just like CTRL-W H. See :h CTRL-W_H in vim.
The small problem with it if you have the hidden option enabled, just closing the window with :q doesn't unload the help window buffer, and if you want to open it again, it will not trigger the FileType event for some reason (why?), so if you use :set hidden you need to:

autocmd FileType help set bufhidden=unload

to get help windows unload, which is the default behavior anyway.

心欲静而疯不止 2024-12-12 17:36:26

它只会在您按另一个键(例如空格)后展开,

也许您可​​以做到

cabbrev <silent> he vert botright help

然后养成快速说:he的习惯空格Enter 或实际上

:he topic

这将扩展为完整命令

编辑

如果您根本不想扩展,我建议使用自定义命令:

:command! Help vert botright help

It will only expand after you press another key (e.g. Space)

Perhaps you can make it

cabbrev <silent> he vert botright help

And then make it a habit to quickly say :heSpaceEnter or indeed

:he topic

Which will then expand to the full command

Edit

If you don't want the expansion at all, I suggest a custom command:

:command! Help vert botright help
独留℉清风醉 2024-12-12 17:36:26

尽管您的答案可以在同一窗口上查看两个帮助主题(例如::h bar | h foo),但在不同窗口上查看两个条目并不是最佳选择(例如:h foo | sp | wincmd w | h bar),即使您的显示器只能显示两个 80 列窗口,它也会在第二个窗口上执行 wincmd

将以下行添加到 ~/.vim/ftplugin/help.vim 中,仅当有空间进行另一个垂直分割时才执行 wincmd

" Only do this when not done yet for this buffer
if exists("b:did_ftplugin")
   finish
endif

if min(map(range(winnr('
)), 'winwidth(v:val)')) > 160
   wincmd L
endif

Although your answer works to see two help topics on the same window (e.g.: :h bar | h foo), it is not optimal to see two entries on different windows (e.g.: h foo | sp | wincmd w | h bar), as it executes also executes the wincmd on the second window thus leaving three vertical windows, even if your monitor can display only two 80 columns windows.

Adding the following lines to ~/.vim/ftplugin/help.vim executes the wincmd only when there is room for another vertical split.

" Only do this when not done yet for this buffer
if exists("b:did_ftplugin")
   finish
endif

if min(map(range(winnr('
)), 'winwidth(v:val)')) > 160
   wincmd L
endif
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文