简体   繁体   English

如何在GVIM中显示标签关闭按钮?

[英]How to show tab close button in GVIM?

Please let me know how to show the close button on each tab page in GVIM. 请告诉我如何在GVIM的每个标签页上显示关闭按钮。

Also, is it possible to set a warning if I am closing GVIM with multiple tab pages open? 此外,如果我打开多个标签页关闭GVIM,是否可以设置警告?

Short Answer 简答

Use buffers effectively! 有效使用缓冲!

Long answer 答案很长

You might consider use :tabclose to close your tabs. 您可以考虑使用:tabclose来关闭标签。 This has the benefit of closing the tab (and keeping you away from your mouse) but also being just annoying enough to motivate a workflow change over to using buffers and splits. 这有利于关闭选项卡(并让您远离鼠标),但也足够烦人,以促使工作流程转换为使用缓冲区和拆分。 As for a warning about closing a tab with multiple windows, I see little benefit if you have 'hidden' set then the buffers are still there so no harm. 关于关闭带有多个窗口的选项卡的警告,如果你有'hidden'设置,那么我认为缓冲区仍然存在,所以没有任何伤害。 If you do not have 'hidden' than any modified buffers will be prompted before they are closed. 如果您没有'hidden' ,则在关闭之前将提示任何已修改的缓冲区。

Why not tabs 为什么不选项卡

Tab pages are great. 标签页很棒。 However it all comes down to vim treating tab pages as more of view-ports into a group of windows or workspaces. 然而,这一切都归结为vim将标签页面视为一组窗口或工作区中的更多视口。 Tab pages just don't scale well. 标签页不能很好地扩展。 Just open some other GUI editor and open up 20 or so tabs. 只需打开一些其他GUI编辑器并打开20个左右的选项卡。 It becomes tricky to deal with. 处理变得棘手。 I have had over a 100 buffers open and switch between them without worrying. 我打开了超过100个缓冲区并在它们之间切换而不用担心。 Buffers just scale in ways that tabs do not. 缓冲区只是以标签没有的方式缩放。 Buffers and splits also work well with smaller windows which is often the case when using terminals. 缓冲器和分离器也适用于较小的窗口,这通常是使用终端时的情况。

Don't just take my word for it. 不要只听我的话。 Here are some more supporting information: 以下是一些更多支持信息:

Quick Buffer Tips and Tricks 快速缓冲提示和技巧

  • set hidden will hide buffers when abandoned. set hidden将在放弃时隐藏缓冲区。
  • Use :sb to switch to a buffer you already opened. 使用:sb切换到已打开的缓冲区。
  • :sb and :b both can take partial names and globs. :sb:b都可以采用部分名称和整数。 eg :sb foo* 例如:sb foo*
  • Take a look at 'switchbuf' and change to your preferences. 看看'switchbuf'并改变你的喜好。
  • Learn to love :sp , :new , and all type of split commands. 学会爱:sp:new ,以及所有类型的拆分命令。
  • Learn some <cw> commands to make your life with splits easier. 学习一些<cw>命令,让你的分裂更轻松。
  • Use capital letter marks to jump back to buffers where you know you will jump back to. 使用大写字母标记跳回到您知道将跳回的缓冲区。
  • Use tags to jump to definitions. 使用标签跳转到定义。
  • Possibly use cscope along with tags 可能使用cscope和标签
  • Use <c-6> to switch to the previously edited file. 使用<c-6>切换到先前编辑的文件。
  • Use <co> and <ci> to move older/newer positions in your jump list. 使用<co><ci>在跳转列表中移动旧/新位置。
  • Possibly make use of one of the many buffer plugins out there. 可能会使用其中一个缓冲插件。 eg CtrlP 例如CtrlP

For more information see: 有关更多信息,请参阅

:h :sb
:h windows
:h 'hidden'
:h 'swb'
:h ctrl-6
:h ctrl-o
:h tags
:h cscope
:h tab-page-commands

Showing the close button 显示关闭按钮

The 'tabline' option can include a %X marker for the close tab button, but that only works for the console version of the tab line. 'tabline'选项可以包含关闭选项卡按钮的%X标记,但这仅适用于选项卡行的控制台版本。 :help 'guitablabel' explicitly states: :help 'guitablabel'明确指出:

Note that syntax highlighting is not used for the option. 请注意,语法突出显示不用于该选项。 The %T and %X items are also ignored. %T和%X项也被忽略。

So, to literally get what you want, you'd have to switch to the (uglier) text-based tab line with 因此,要真正得到你想要的东西,你必须切换到(丑陋的)基于文本的标签行

:set guioptions-=e

But note that using the mouse (even though you may be customized to that by other applications like web browser tabs) is discouraged in Vim. 但请注意,在Vim中不鼓励使用鼠标(即使您可以通过Web浏览器选项卡等其他应用程序对其进行自定义)。 If you right mouse button-click on a GUI tab label, you can alternatively also choose |Close tab| 如果您在鼠标右键上单击GUI选项卡标签,您也可以选择|Close tab| from the popup menu. 从弹出菜单中。

Preventing tab close 防止标签关闭

(Note that asking multiple questions is frowned upon here; please ask them separately.) (请注意,在这里提出多个问题是不赞成的;请单独询问。)

I don't think this is possible; 我不认为这是可能的; there is a VimLeavePre event that you could hook into, but it cannot prevent the closing of Vim; 有一个你可以挂钩的VimLeavePre事件,但它不能阻止关闭Vim; the action (eg :qall! ) cannot be undone. 动作(例如:qall! )无法撤消。 If you are used to closing Vim always via a mapping or command, you could overwrite that and include a check in there (using tabpagenr('$') > 1 ). 如果您习惯于通过映射或命令关闭Vim,则可以覆盖它并在其中包含一个检查(使用tabpagenr('$') > 1 )。

If you're concerned with losing your window / tab layout, rather have a look at Vim sessions (which can be persisted automatically in the background). 如果您担心丢失窗口/标签布局,请查看Vim会话 (可以在后台自动保留)。 This will allow to re-launch Vim with the previously opened windows. 这将允许使用先前打开的窗口重新启动Vim。

If you need this, you are probably doing it wrong. 如果你需要这个,你可能做错了。 You don't need mouse with vim. 你不需要带vim的鼠标。

But how about 但是怎么样

nnoremap <MiddleMouse> :tabclose<CR> 

Other then that see TabLineSet.vim : A Vim7 tabline customization which has 其他那些看到TabLineSet.vim:一个Vim7 tabline定制

closers : add hot spots ("!") to the tab for click-to-close 闭包器:在标签上添加热点(“!”)以便点击关闭

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

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