Search code examples
buttonvimtabswarningstabpage

How to show tab close button in GVIM?


Please let me know how to show the close button on each tab page in GVIM.

Also, is it possible to set a warning if I am closing GVIM with multiple tab pages open?


Solution

  • 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. :help 'guitablabel' explicitly states:

    Note that syntax highlighting is not used for the option. The %T and %X items are also ignored.

    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. If you right mouse button-click on a GUI tab label, you can alternatively also choose |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; the action (e.g. :qall!) cannot be undone. 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).

    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). This will allow to re-launch Vim with the previously opened windows.