28

I usually work in a drop-down terminal, running about 25 characters high. Since I prefer tabs to windows1, usually a lot of horizontal space is wasted - around half of the terminal width.

On top of that, Vim, with the default setting of helpheight, leaves just about a couple of lines of the file content when I open a help window:

enter image description here

Is there a way to make :h use a vertical split?

I could:

  • decrease helpheight
  • use <C-W>L to manually move the window
  • make a map or a custom command which does the above for me.

Is there a simpler way?

1I do use windows when I need to look at multiple files together. But usually I prefer each file to be in its own (mental) context.

4
  • @statox sorry about that. Dunno what I was thinking when I wrote that.
    – muru
    Commented Aug 22, 2015 at 19:38
  • Ahah no need to be sorry it also happens to the best ones ;-)
    – statox
    Commented Aug 22, 2015 at 19:39
  • The same question on SO: stackoverflow.com/questions/630884/… Commented May 30, 2020 at 22:03
  • It is sometimes even better to use :tab help So that current layout is not affected
    – balki
    Commented Jan 4, 2023 at 1:57

5 Answers 5

26

You can use :vert h [your topic] to open help vertically.

You can use the following command:

cnoreabbrev H vert h

To make vim replace H by vert h automatically in command line.

Also you can use this abbreviation:

cnoreabbrev HR vert bo h

To open the help window on the right side of the screen. (see :h :botright for more details on bo)

5
  • So, no configurable option? Something like splitright for :help?
    – muru
    Commented Aug 22, 2015 at 19:31
  • I'm not sure to understand what you mean, you'd prefer to be able to choose where the help window should be placed?
    – statox
    Commented Aug 22, 2015 at 19:35
  • I think you meant :rightbelow instead of :botright.
    – muru
    Commented Aug 22, 2015 at 21:26
  • 2
    Well it depends on the behavior you are expecting, let says that you should play with :lefta[bove], :rightb[elow], :to[pleft] and :bo[tright] and see which one you prefer. I prefer :botright over :rightbelow because what ever my layout is, I'll get a help windows of the full height of the screen. With :rightbelow is I already have an horizontal split my help window will be of the height of this split.
    – statox
    Commented Aug 22, 2015 at 22:01
  • 3
    Sadly, writing correct cabbrev commands involves some ritual. Commented Aug 23, 2015 at 11:21
9

This is inspired from junegunn 's vimrc:

augroup vimrc_help
  autocmd!
  autocmd BufEnter *.txt if &buftype == 'help' | wincmd L | endif
augroup END
3
  • 2
    I'm curious: how does this differ from autocmd FileType help wincmd L? Any edge cases?
    – muru
    Commented Aug 22, 2015 at 21:28
  • I think that gets triggered twice, at least sometimes (try adding an echo there). It might be something to do with the help window opening, than going to the specific help tag. So, the BufEnter would be slightly more efficient. Not to mention adding a command that, when triggered twice, would become "undone" (cancel itself).
    – VanLaser
    Commented Aug 22, 2015 at 21:34
  • works fine, if you prefer to open on the left side use .. wincmd H .
    – abu_bua
    Commented May 12, 2022 at 21:18
7

You can use a custom command that does the vertical-or-not selection for you. This can be based on the current window width and height :

function! s:ShowHelp(tag) abort
  if winheight('%') < winwidth('%')
    execute 'vertical help '.a:tag
  else
    execute 'help '.a:tag
  endif
endfunction

command! -nargs=1 H call s:ShowHelp(<f-args>)

References :

  • :h winheight
  • :h <f-args>
1
  • Excellent. This will be very useful for the times I have gvim open covering a vertical half of my screen.
    – muru
    Commented Aug 22, 2015 at 22:11
1

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

While this isn't a vertical split per-se, I find having help in its own tab to be very nice.

augroup HelpInTabs
autocmd!
   autocmd BufEnter *.txt call HelpInNewTab()
augroup END

Whoops. I thought I had pasted the whole answer. Here's the rest of the code.

" only apply to help files...
function! HelpInNewTab ()
  if &buftype == 'help'
    " convert help window to a tab
    execute "normal \<C-W>T"
  endif
endfunction
2
  • 1
    That would be a good idea to also show what is your HelpInNewTab() function because I think this isn't a built-in feature so we can't really test your solution.
    – statox
    Commented Aug 22, 2015 at 20:41
  • " only apply to help files... function! HelpInNewTab () if &buftype == 'help' " convert help window to a tab execute "normal \<C-W>T" endif endfunction Commented Mar 19, 2018 at 13:08

Your Answer

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

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