42

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?

13 Answers 13

54

Just expand the help window to be the only visible window: Ctrlw-o

When you're done you can switch back to your other buffers.

2
  • 4
    Similarly, you can switch to the other window with Ctrl-w w and close it with Ctrl-w c, leaving you with just the help. – bsmith89 Feb 4 '15 at 23:47
  • Picking highest voted answer. – Ruslan Osipov Feb 5 '15 at 0:06
27

Alternatively, you could open the help window in a new tab: :tab help foo, and then use :q to close it.

2
  • 2
    Is there also a way to do this by default? So that :help foo would act as :tab help foo? – Martin Tournoij Feb 6 '15 at 14:44
  • 2
    @Carpetsmoker Yes, you could do something like cnoremap help tab help. – Doorknob Feb 6 '15 at 14:45
20

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.

9

You can move the help screen to its own tab with

ctrl+w T (note the T is upper case).

Then you can switch between the tabs with gt.

6

You can make the help window full width and height by eliminating all other split windows, using Control-wo while inside the help window. This command makes the current window the only window, removing all other windows.

4

Another option that gets rid of the pesky extra "new file" tab is vim +"tab help | -tabc". This creates a help tab on vim start (tab help) and removes the new file (-tabc).

2

You can also the command:only. It's the same with C-W C-O couple. More on :h only

2
  • 1
    Welcome to this site Adem, we usually encourage our users to explain why they recommend using a specific command and how it works. It is also usually a best practice to link the relevant help topic like :h :only – statox Jan 15 '20 at 12:28
  • 1
    Got it and changed. Thank you very much. – user26514 Jan 15 '20 at 12:36
2

My personal variation:

command! -nargs=1 -complete=help H help <args> | silent only

This let's you to use :H as you would normally use :help.

only then does the Ctrlw-o combo that others have mentioned.

1
2

I'm rarely use tabs, but if I make a help window :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
1

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> )
1

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 :help ....

1

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 exec "tabo" (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.

0

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('')[0].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 0.

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 getbufinfo('')[0].loaded is 1 or 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: Thank you @statox for suggesting using an augroup for making sure the autocmd trigger doesn't get set multiple times (see why it's a good idea).

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.

New contributor
webninja is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
5
  • A few remarks: 1) I don't think you need the + in +close (or at least this is a syntax you don't see in most vimscript files) 2) Don't forget to always put your autocmd in an augroup otherwise if you re-source your vimrc the autocmd is executed twice and that can create issues 3) I didn't test the code so I don't have the right solution but your timer workaround seems a bit overkill I think you could have the same result without a timer if you use the correct autocmd event :h autocmd-events – statox Jul 30 at 10:57
  • Thank you for your suggestions, @statox. Good call on suggesting that autocmds be grouped with augroup. You just taught me something valuable. The +close action may be rarely used, but it's an actual command that closes the last window (rather than the current one). I saw a similar heuristic advertised under :h tabclose for tabs and tried it with close for windows and it works as expected. If you simply write close it will close the help window that you've just opened rather than the one we're trying to close. – webninja 2 days ago
  • The reason for the timer stratagem is because I couldn't find an event that fires precisely when we need it. If that can be solved that would be fantastic. It also introduces an unfortunate side effect where the view flickers as the help content is first rendered before the other window is closed. I of course looked for a way to temporarily disable redrawing to eliminate the flickering but so far I haven't found a solution. – webninja 2 days ago
  • I also switched from using autocmd filetype help to autocmd BufNew *.txt because with the first strategy I was having difficulties making the action idempotent. If you opened help from an empty buffer, then as you cycle between the two alternate buffers, when switching back to the help it would keep triggering the logic and closing one of the other windows until no other windows were left. I also tried using bunload # and bwipeout # (the second option simply destroys the alternate buffer), but it became clear that we need to target the window and not the buffer to get this right. – webninja 2 days ago
  • If you start vim with vim "+new +1b | +new +1b | +new +1b", it will open four windows all showing the same unmodified empty buffer. With buffer unloading, it would at once close all of those windows when you open help because you just unloaded the buffer that they were showing. That is why we need to be closing the window. – webninja 2 days ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.