I know I can browse Vim help with
:help, but this opens a split. Sometimes, I just like to study documentation. How read documentation in a "full screen" mode?
The other answers have already answered your question, but for the sake of completeness:
If you just want to temporarily get a larger window for your help-viewing, you can use either or both of the
Ctrl-w _ and
Ctrl-w | mappings to maximise the help window as much as possible vertically or horizontally, respectively, but without closing your existing split windows.
When you subsequently close the help window with
Ctrl-w c or
:q, your window layout will be returned to exactly how it was before you opened the help window.
This is useful if you have a slightly more complicated window layout which you would like to preserve.
I'm rarely use tabs, but if I make a
:only, (which is what I have done in the past), and then I switch to the file buffer to try what I learned, the
help buffer is gone, and I have to reopen it and re-navigate to the place where I was before to continue reading the help content.
After reading all the answers here, I find that for me :tab is the right solution. The biggest bonus is that I can swap back and forth (
gt) between the file buffer tab and the help tab without losing my place, at the cost of one line of terminal real estate.
And, to open help initially in a new tab:
:tab help xxyyzz
I often open a new vim instance in another workspace/screen just to pop open a help window so this article was enormously helpful to me.
Here Is a bit of VimScript that I just wrote that will open a
help page in a new tab, and automatically close a new/empty buffer if necessary. Hopefully it is useful to folks in the future. Thank y'all for your help!
" Help: Open a `help` page in a new tab, or replace the current buffer if it " is unnamed and empty. function! Help( query ) " Is the current buffer empty? let l:empty = line( '$' ) ==# 1 && getline( 1 ) ==# '' " Store the current tab number so we can close it later if need be. let l:tabnr = tabpagenr() let l:bufname = bufname( winbufnr( 0 ) ) try " Open the help page in a new tab. (or bail if it's not found) execute "tab help " . a:query " The help page opened successfully. Close the original tab if it's empty. if l:bufname ==# '' && l:empty execute "tabclose " . l:tabnr endif endtry endfunction command! -nargs=1 Help call Help( <f-args> )
I wrote a tiny plugin to do this a few years ago: vim-helptab. It opens help docs in their own tab when you type
:h .... To bypass it you can do
:he ... or
I found this on the vim.fandom.com website. It works by making a session before maximizing, then it reloads the previous session view.
Because I have lots of tabs, I had to add
(tabonly) before reloading the session, otherwise you end up with double the number of tabs.
nnoremap <a-m> :call MaximizeToggle()<CR> function! MaximizeToggle() if exists("s:maximize_session") exec "tabo" exec "source " . s:maximize_session call delete(s:maximize_session) unlet s:maximize_session let &hidden=s:maximize_hidden_save unlet s:maximize_hidden_save else let s:maximize_hidden_save = &hidden let s:maximize_session = tempname() set hidden exec "mksession! " . s:maximize_session only endif endfunction
However, when working with a lot of files, I found this 'reload session' method lagged a bit. Maybe someone can comment on how to reduce the lag.
Put this in your
.vimrc for help to open in place of an unmodified empty buffer instead of alongside it in a split window:
" Is a buffer an unmodified empty buffer fun! IsBufferEmptyAndUnmodified(which) return bufname(a:which) == '' && !getbufvar(a:which, "&modified") endfun fun! CloseEmptyBufferWindow(timer) " If we're viewing help and the other buffer is an unmodified empty one if &filetype == "help" && getbufinfo('').loaded && IsBufferEmptyAndUnmodified('#') " Close the last window that had focus +close endif endfun " Set trigger to hide unmodified empty buffer when opening help augroup fixhelp au! autocmd BufNew *.txt call timer_start(0, 'CloseEmptyBufferWindow') augroup end
When you open help, what is known as the alternate file buffer reference is set to the file you were editing right before help was opened. You can see that by pressing Ctrl6, which will switch back and forth between the two alternate buffers. At any given moment, the current window's alternate buffer is generally referred to by the shorthand alias
If the alternate buffer happens to be an empty
[No Name] scratchpad,
bufname('#') will return an empty string and if that buffer is not in a modified state
getbufvar('#', "&modified") will return
autocmd BufNew *.txt sets a trigger that will perform an action when a text file buffer is created. If the text file is a help file, then
&filetype will equal
"help", and the
+close action closes the last window that had focus. Unfortunately, at that exact point when the trigger fires the alternate buffer entity hasn't been set up yet, so querying the
'#' buffer will actually return information about the buffer displaying the help and not the previously active buffer. That necessitates postponing the action by setting a trivial timer to check the situation and take appropriate action right after the pending setup of the alternate buffer has finished taking place. The other condition to check for happens as a consequence of using the
BufNew event, which also fires multiple times when closing the editor (it must have to do with what happens during the shutdown sequence). Checking whether
0 will allow us to differentiate between the events fired when the help content is loaded and events fired when Vim is shutting down.
EDIT: Switched from using
autocmd filetype help to
autocmd BufNew *.txt because it matches the situation more accurately.
filetype help also triggers when switching back to help from the alternate buffer using Ctrl6 or
:b# because the displayed filetype changes, whereas
BufNew only fires when the buffer is first created.