121
votes

Is there a way to get Vim help to open in a vertical split pane rather than a horizontal one?

10

10 Answers

133
votes

: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
43
votes

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.

21
votes

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.

19
votes

This command should do it:

:vert help
7
votes

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)

7
votes

Put the following in your ~/.vim/ftplugin/help.vim

wincmd L

Can't get simpler than this :)

6
votes

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

3
votes

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.

2
votes

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

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.