Is there a way to get Vim help to open in a vertical split pane rather than a horizontal one?
Is there a way to get Vim help to open in a vertical split pane rather than a horizontal one?
: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
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
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