134

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

13 Answers 13

143

: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
6
  • 3
    how can i map that so when I run :help ____ it always opens like that?
    – Tallboy
    May 7, 2012 at 20:37
  • 17
    @Tallboy Try cnoremap help vert help. This creates a command mode mapping so that when you type help in command mode you will see it expand to vert help. Sep 6, 2012 at 21:31
  • 4
    @Kazark: cnoremap help vert help makes each letter of help appear by itself, so the word help doesn't appear on the command line. Is there any way to fix that? Maybe something other than cnoremap?
    – iconoclast
    May 11, 2014 at 2:26
  • 15
    To improve more: you can use cabbrev to redefine h as vert h: :cabbrev h vert h. Then every time you type :h, it will automatically expand to :vert h.
    – Aaron Shen
    Oct 18, 2015 at 2:39
  • @AaronShen: best solution ( in combo with this answer )!
    – gauteh
    Jan 9, 2018 at 10:03
52

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.

10
  • 3
    Simple, 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!?
    – iconoclast
    May 11, 2014 at 2:31
  • 1
    I 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 simply help. 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
  • 1
    This 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 the help 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
    – EdJoJob
    Jan 28, 2015 at 0:15
  • 1
    This 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.
    – acamso
    Aug 17, 2022 at 1:11
  • 1
    In 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.
    – Steve Ward
    Jan 4 at 0:54
29

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.

1
  • This seems to be the best solution. Thanks!
    – acamso
    Aug 17, 2022 at 0:38
21

This command should do it:

:vert help
2
  • 10
    I don't get this. All :vsplit does is split the current window vertically. How does this open help in a vertical pane?
    – doubleDown
    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...
    – orlp
    Mar 5, 2021 at 16:30
8

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

4
  • 3
    Check the filetype before split, :au BufEnter */doc/* if &filetype=='help' | wincmd L | endif
    – rox
    Feb 10, 2017 at 1:50
  • 1
    This is awesome! autocmd FileType help wincmd L only works one time for me, this works very well!
    – WW00WW
    Aug 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 with if &filetype=='help' does the trick. Also after wincmd L I also do | if winwidth(0) < 78 | wincmd T | ... to reopen it in a new tab if the help window becomes too narrow.
    – Stanislav
    Aug 22, 2022 at 19:04
  • This is the only persistent and reliable solution on this page (BufRead event is not needed, BufEnter suffices).
    – bloody
    Jun 10 at 13:23
7

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

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

wincmd L

Can't get simpler than this :)

1
4

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
})
3

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.

3

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
2

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.

1

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.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.