Is there a way to get Vim help to open in a vertical split pane rather than a horizontal one?
13 Answers
:vertical
(vert
) works:
:vert help
You can also control whether the window splits on the left/top or the right/bottom with topleft
(to
) and botright
(bo
). For example, to open help in the right window of a vertical split:
:vert bo help
-
3how can i map that so when I run :help ____ it always opens like that?– TallboyMay 7, 2012 at 20:37
-
17@Tallboy Try
cnoremap help vert help
. This creates a command mode mapping so that when you typehelp
in command mode you will see it expand tovert help
. Sep 6, 2012 at 21:31 -
4@Kazark:
cnoremap help vert help
makes each letter ofhelp
appear by itself, so the wordhelp
doesn't appear on the command line. Is there any way to fix that? Maybe something other thancnoremap
? May 11, 2014 at 2:26 -
15To improve more: you can use cabbrev to redefine
h
asvert h
::cabbrev h vert h
. Then every time you type:h
, it will automatically expand to:vert h
. Oct 18, 2015 at 2:39 -
As an alternative to Haroogan and Sean's answers you can use the FileType
event for the autocommand like this:
autocmd FileType help wincmd L
Although this will change the position of any help window as well as moving the window after manually placing it if the file you are looking at changes. But I believe that this is a problem with any solution.
-
3Simple, and (if I understand correctly) the side effects are negligible. Why is this not the accepted answer!? And why does a completely irrelevant answer (
:vsplit
) have lots of upvotes!? May 11, 2014 at 2:31 -
1I upvoted both this and Haroogan's answers for their simplicity. I’m not very familiar with autocmd events and I was wondering what the reason is for
help,*
instead of simplyhelp
. Also, I noticed that this command works when I add it to my_vimrc
and start a new instance of GVim but not when I run the command in my current GVim session (I have to manually:set ft=help
to trigger the autocmd). Jun 24, 2014 at 9:56 -
1This autocmd addresses the issue by looking at the filetype of the help files. All help files are of the
help
filetype, thus on the setting of thehelp
filetype this autocmd will run. You can test this by doing:sef help
in any file while there is a split in your window, thus @danbruegge's second autocmd would not be needed– EdJoJobJan 28, 2015 at 0:15 -
1This doesn't seem to persist here. Couldn't put my finger on it, but it would work fot a bit then switch back to a horizontal split. @Alexander Shukaev 's answer seems to work best and is probably best practice.– acamsoAug 17, 2022 at 1:11
-
1In neovim,
autocmd FileType help wincmd L
only happens the first time a help window is opened. Try opening a help window, closing it, then opening a help window. After the first help window, the rest are opened in a horizontal split. Jan 4 at 0:54
No need to remap any commands or introduce weird aliases like :Help
. Here is the solution. Create ~/.vim/after/ftplugin/help.vim
where you can override any Vim settings particularly for help
and add the following line there:
autocmd BufWinEnter <buffer> wincmd L
This hook will ensure that any help
file is opened in vertical split. Furthermore, it does not have a side effect described in Sean's answer. Personally, this is perfect solution for me so far.
Hope this helps. Best of luck.
This command should do it:
:vert help
-
10I don't get this. All
:vsplit
does is split the current window vertically. How does this open help in a vertical pane? Jun 3, 2013 at 9:17 -
1@doubleDown 7 years later...
:vert
is not the same as:vsplit
. From the docs: ":vert {cmd}
, Execute {cmd}. If it contains a command that splits a window, it will be split vertically." EDIT: oh your comment was posted when this answer was incorrect...– orlpMar 5, 2021 at 16:30
To make help files always open in a vertical split on the right, put this in your vimrc:
augroup helpfiles
au!
au BufRead,BufEnter */doc/* wincmd L
augroup END
This will have the side effect of having anything with "doc" in its path open in a vertical split, but that may not be a problem for you. It isn't for me. If you would rather it open in a left vertical split, or anything else for that matter, you can change wincmd L
. You can learn more about it with :he wincmd
-
3Check the filetype before split,
:au BufEnter */doc/* if &filetype=='help' | wincmd L | endif
– roxFeb 10, 2017 at 1:50 -
1This is awesome!
autocmd FileType help wincmd L
only works one time for me, this works very well!– WW00WWAug 21, 2018 at 10:26 -
This one works for neovim.
autocmd FileType
doesn't work in neovim if you close and reopen help because help buffer remains hidden. But BufEnter withif &filetype=='help'
does the trick. Also afterwincmd L
I also do| if winwidth(0) < 78 | wincmd T | ...
to reopen it in a new tab if the help window becomes too narrow. Aug 22, 2022 at 19:04 -
This is the only persistent and reliable solution on this page (
BufRead
event is not needed,BufEnter
suffices).– bloodyJun 10 at 13:23
Put this in your .vimrc
:
command -nargs=* -complete=help Help vertical belowright help <args>
Now you can open a vertical help with the :Help
command (notice that the first-letter is uppercase)
Put the following in your ~/.vim/ftplugin/help.vim
wincmd L
Can't get simpler than this :)
-
This doesn't work anymore. See this issue on Github: github.com/vim/vim/issues/1806 Jan 19, 2018 at 14:38
Here's an autocmd in lua for neovim.
-- Open help window in a vertical split to the right.
vim.api.nvim_create_autocmd("BufWinEnter", {
group = vim.api.nvim_create_augroup("help_window_right", {}),
pattern = { "*.txt" },
callback = function()
if vim.o.filetype == 'help' then vim.cmd.wincmd("L") end
end
})
This moves the help window once. So you can freely move it around after the window is created.
if has('autocmd')
function! ILikeHelpToTheRight()
if !exists('w:help_is_moved') || w:help_is_moved != "right"
wincmd L
let w:help_is_moved = "right"
endif
endfunction
augroup HelpPages
autocmd FileType help nested call ILikeHelpToTheRight()
augroup END
endif
The function, ILikeHelpToTheRight()
will only run wincmd L
once per window (it's what the w:
prefix is for).
This is then called whenever a "help" file is opened. This doesn't have the side-effects of EdJoJob's solution.
Dynamically open help windows at the top if there's more than one window in current tab, or on the right, if there's only one window:
if winnr('$') > 2
wincmd K
else
wincmd L
endif
You'll need to place this in ftplugin/help.vim
or use it with an autocmd
, e.g.:
augroup my_filetype_settings
autocmd!
autocmd FileType help if winnr('$') > 2 | wincmd K | else | wincmd L | endif
augroup END
This is meant to add to @m42's answer, but I don't have 50 rep yet here on SO proper to add to the comments.
Add nnoremap <C-H> :vert bo help
to .vimrc
Now pressing Ctrl-H in Normal mode will jump into Command mode, prefixed to open help in a vertically split window to the right.
Include a trailing space after help·
<-- at the end of the config line for best results.
This mapping allows you to still use :help
\ :h
to open a horizontally split window or cycle through your previous help command history without the prompt auto-expanding.
I settled on the following:
" Open help in a vertical split or a new tab.
augroup my_help
" Remove current group to avoid double runs
autocmd!
" If a help buffer is opened then try to move it to the right. If now it
" doesn't fit help text (78 chars) then move it to a new tab.
autocmd BufEnter * if &filetype == 'help' | wincmd L | if winwidth(0) < 78 | wincmd T | endif | endif
augroup END
It works for me in both vim and neovim.
FileType help
doesn't work in neovim if I reopen help because the help buffer remains hidden in neovim while vim seems to unload it.
This is what I use, taken from docwhat's answer. You can change values to your liking.
function! MoveWindowToRightOrNewTab()
if winwidth(0) < 165
wincmd T
else
wincmd L
vert resize 85
endif
endfunction
" Open help in a vertical split or a new tab.
augroup HelpWindowOnRight
" Remove current group to avoid double runs
autocmd!
" If a help buffer is opened then try to move it to the right. If now it
" doesn't fit help text (80 chars) then move it to a new tab.
autocmd FileType help call MoveWindowToRightOrNewTab()
augroup END