I know I can browse Vim help with :help, but this opens a split. Sometimes, I just like to study documentation. How can I read the Vim documentation in a "full screen" mode?
- 217
- 1
- 7
- 893
- 1
- 7
- 10
-
Shameless plug: See my answer below for a solution that perfoms it all automatically, and does even more. – dsimic Jan 14 '24 at 02:25
17 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.
- 2,481
- 20
- 13
-
5Similarly, you can switch to the other window with
Ctrl-w wand close it withCtrl-w c, leaving you with just the help. – bsmith89 Feb 04 '15 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) – Pound Hash Mar 23 '22 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. – Pound Hash Mar 23 '22 at 20:02
-
Try
:lsto see a list of your open buffers and:b<N>(where N is a numbered buffer) to switch to one of them.Also, since you're already browsing the help, check out
– bsmith89 Mar 31 '22 at 19:40:help buffersto learn more. ;) -
Alternatively, you could open the help window in a new tab: :tab help foo, and then use :q to close it.
- 15,237
- 3
- 48
- 70
-
2Is there also a way to do this by default? So that
:help foowould act as:tab help foo? – Martin Tournoij Feb 06 '15 at 14:44 -
3@Carpetsmoker Yes, you could do something like
cnoremap help tab help. – Doorknob Feb 06 '15 at 14:45 -
1"...and then use :q to close it." we could also add, or use
gtto switch between tabs. – Pound Hash Mar 23 '22 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.
- 31,891
- 3
- 72
- 139
-
Ctrl-w |doesn't seem to do anything.Ctrl-w _does display help to nearly full screen though. – Pound Hash Mar 23 '22 at 20:05 -
2This is really cool and useful. And if want to display all the windows again with same size, use
Ctrl-w =@PoundHash
– Leandro Mar 26 '22 at 11:57Ctrl-w |is for vertical splits andCtrl-w _for horizontal splits
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.
- 950
- 8
- 6
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).
- 171
- 1
- 2
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.
- 2,818
- 2
- 14
- 27
this may be the simplest way to achieve this
vim +"help | only"
or the same as
vim +help +only
- 61
- 1
- 1
You can also the command:only. It's the same with C-W C-O couple. More on :h only
-
1Welcome 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
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.
- 191
- 4
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
- 131
- 2
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> )
- 11
- 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,349
- 8
- 13
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.
- 11
- 1
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.
- 1,213
- 1
- 14
- 28
- 176
- 1
- 4
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.
- 61
- 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 yourautocmdin anaugroupotherwise 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 '21 at 10:57 -
Thank you for your suggestions, @statox. Good call on suggesting that
autocmds be grouped withaugroup. You just taught me something valuable.The
– webninja Aug 01 '21 at 07:27+closeaction 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 tabclosefor tabs and tried it withclosefor windows and it works as expected. If you simply writecloseit will close the help window that you've just opened rather than the one we're trying to close. -
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 Aug 01 '21 at 07:28
-
I also switched from using
autocmd filetype helptoautocmd BufNew *.txtbecause 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. – webninja Aug 01 '21 at 07: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. – webninja Aug 01 '21 at 10:24
If you are a tmux user as well, check out https://github.com/dhruvasagar/vim-zoom. Maps seamlessly.
- 101
This is an excerpt from my ~/.vimrc that performs automatically pretty much exactly what the OP asked for, which I also find extremely useful:
" Maximize the help window automatically upon opening
"
augroup vimrc-help-window
autocmd!
autocmd BufWinEnter * if &l:buftype ==# "help" | wincmd _ | endif
augroup END
This is an improved version that also centers the help window automatically upon opening at the resulting position, for additional reading comfort:
" Maximize the help window automatically upon opening, and automatically
" center the help window vertically at the resulting position
"
" NOTE: Obviously, setting up a timer isn't the best solution, but I see
" no better way to have ":normal zz" executed properly
"
function! CenterHelp(timer)
execute "normal zz"
endfunction
augroup vimrc-help-window
autocmd!
autocmd BufWinEnter *
\ if &l:buftype ==# "help"
\ | wincmd _
\ | call timer_start(200, "CenterHelp", {"repeat": 1})
\ | endif
augroup END
Instead of using an augroup and autocmd to maximize the help window upon opening, the following configuration line can be used instead in ~/.vimrc:
set helpheight=9999
This solution also seemingly better preserves the position of the main edited document and the cursor within it after closing the help window.
If you want to also automatically position the help window vertically at the resulting help tag position upon opening, below is the adjusted version of the above-provided additional vimscript code.
This version of the vimscript code no longer exactly centers the help window vertically at the displayed help subject tag, but also scrolls the help window down a bit so the displayed help section starts at about 1/3 of the window heigh, for even better reading comfort. In my experience, positioning the help window this way is much more useful than simply centering it vertically.
" Automatically position the help window vertically upon opening at the
" resulting position of the displayed help subject tag, so the desired
" help section starts at about 1/3 of the help window height
"
" NOTE: Obviously, setting up a timer isn't the best solution, but I see
" no better way to have the commands executed properly
"
function! PositionHelp(timer)
set lazyredraw
execute "normal zz"
execute "normal! " .. float2nr(winheight(0) / 5) .. "\<C-E>"
set nolazyredraw
endfunction
augroup vimrc-help-window
autocmd!
autocmd BufWinEnter *
\ if &l:buftype ==# "help"
\ | call timer_start(200, "PositionHelp", {"repeat": 1})
\ | endif
augroup END
The last version of the vimscript code, available right above, has some inherent issues, such as scrolling beyond the end of the buffer and producing blank lines, or scrolling the window down when the start of the displayed help subject is already within the first third of the window height.
I've implemented an improved version of the vimscript code that doesn't suffer from the above-described issues, and additionally handles both :h (i.e. no subject specified and no additional vertical positioning) and :h <subject> (i.e. vertical positioning at the specified subject) properly. Though, I'll provide that version of the vimscript code only if someone asks for it in the comments, because it's a sizable chunk of code and this answer is already quite long.
- 217
- 1
- 7