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?
16 Answers
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.
-
5Similarly, you can switch to the other window with
Ctrl-w w
and close it withCtrl-w c
, leaving you with just the help.– bsmith89Feb 4, 2015 at 23:47 -
-
2
-
2@bsmith89 This didn't work for me. The help goes full screen, but Ctrl-w w doesn't show me any other window. (Vim 8.2) Mar 23, 2022 at 20:02
-
2The main answer doesn't explain how to switch to other buffers. After my help screen becomes full, I don't know how to return to original window. Mar 23, 2022 at 20:02
Alternatively, you could open the help window in a new tab: :tab help foo
, and then use :q
to close it.
-
2Is there also a way to do this by default? So that
:help foo
would act as:tab help foo
? Feb 6, 2015 at 14:44 -
3@Carpetsmoker Yes, you could do something like
cnoremap help tab help
.– DoorknobFeb 6, 2015 at 14:45 -
1"...and then use :q to close it." we could also add, or use
gt
to switch between tabs. Mar 23, 2022 at 20:12
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.
-
Ctrl-w |
doesn't seem to do anything.Ctrl-w _
does display help to nearly full screen though. Mar 23, 2022 at 20:05 -
2This is really cool and useful. And if want to display all the windows again with same size, use
Ctrl-w =
@PoundHashCtrl-w |
is for vertical splits andCtrl-w _
for horizontal splits– LeandroMar 26, 2022 at 11:57
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
.
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.
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
).
this may be the simplest way to achieve this
vim +"help | only"
or the same as
vim +help +only
You can also the command:only
. It's the same with C-W C-O
couple. More on :h only
-
1
-
1Got it and changed. Thank you very much.– user26514Jan 15, 2020 at 12:36
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
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
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 :help ...
.
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.
If a screen size is available where vim has ~160 columns :vertical help ...
might also be an option. Then the help-page is in 'full screen' and there is space enough for another buffer for experimenting.
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.
-
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 yourautocmd
in anaugroup
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
– statoxJul 30, 2021 at 10:57 -
Thank you for your suggestions, @statox. Good call on suggesting that
autocmd
s be grouped withaugroup
. 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 withclose
for windows and it works as expected. If you simply writeclose
it will close the help window that you've just opened rather than the one we're trying to close.– webninjaAug 1, 2021 at 7:27 -
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.– webninjaAug 1, 2021 at 7:28
-
I also switched from using
autocmd filetype help
toautocmd 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 usingbunload #
andbwipeout #
(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.– webninjaAug 1, 2021 at 7:39 -
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.– webninjaAug 1, 2021 at 10:24
If you are a tmux
user as well, check out https://github.com/dhruvasagar/vim-zoom
. Maps seamlessly.