16

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.

  • @statox sorry about that. Dunno what I was thinking when I wrote that. – muru Aug 22 '15 at 19:38
  • Ahah no need to be sorry it also happens to the best ones ;-) – statox Aug 22 '15 at 19:39
15

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)

  • So, no configurable option? Something like splitright for :help? – muru Aug 22 '15 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 Aug 22 '15 at 19:35
  • I think you meant :rightbelow instead of :botright. – muru Aug 22 '15 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 Aug 22 '15 at 22:01
  • 2
    Sadly, writing correct cabbrev commands involves some ritual. – Sato Katsura Aug 23 '15 at 11:21
6

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>
  • Excellent. This will be very useful for the times I have gvim open covering a vertical half of my screen. – muru Aug 22 '15 at 22:11
5

This is inspired from junegunn 's vimrc:

augroup vimrc_help
  autocmd!
  autocmd BufEnter *.txt if &buftype == 'help' | wincmd L | endif
augroup END
  • 1
    I'm curious: how does this differ from autocmd FileType help wincmd L? Any edge cases? – muru Aug 22 '15 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 Aug 22 '15 at 21:34
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
  • 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 Aug 22 '15 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 – Mark Nichols Mar 19 '18 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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