1

I would like to redefine the :h and :help commands, so that they split the screen vertically by default. The following solutions are undesirable for two reasons.

cnoremap h vert help
cabbrev h vert help
  1. I only want the substitution to occur for :* commands. Unfortunately, the substitution also occurs when I type /h. I scanned through the documentation on maps, but I could not find a command that will only remap :* commands and not /* commands.

  2. I only want the substitution to occur when the command starts with :h. If I type :ah, the command is expanded to :avert help. This behavior may be desirable when I pipe commands together, but I don't want it here.

Thanks for your help!

void-pointer
  • 14,247
  • 11
  • 43
  • 61
  • 1
    I strongly advise you to give Kent's answer a shot as it's very simple. If you really want to redefine the command you can limit this redefinition to only `:` commands (see `:h getcmdtype()`). See https://github.com/rson/vimscript-snippets/blob/master/lowercase_commands.vim for an example of how to use this. – Randy Morris Apr 25 '13 at 23:55
  • @RandyMorris I had actually come across an article where I just read about `getcmdtype()`, but Kent's answer is a lot cleaner. Unfortunately, I have a funny issue which I commented about below Kent's answer. – void-pointer Apr 25 '13 at 23:56

3 Answers3

3

I would use the cmdalias.vim - Create aliases for Vim commands plugin for that, but you can also solve this with a clever mapping:

:cnoreabbrev <expr> h getcmdtype() == ":" && getcmdline() == "h" ? "vert h" : "h"
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • Thanks, this solution works well. Personally, I would replace `vert` with `vert belowright`, as this opens the help window in the right panel. – void-pointer Apr 26 '13 at 06:49
  • In response to my previous comment: actually, no I would not recommend replacing `vert` with `vert belowright`. Setting `set splitright` is a better idea. – void-pointer Apr 26 '13 at 07:32
2

I would like to redefine the :h and :help commands, so that they split the screen vertically by default.

In my vimrc, I have:

"====================
"Help in vertical split (right)
"====================
autocmd FileType help wincmd L

if you want the help show in left vertical split, use H instead of L

Kent
  • 189,393
  • 32
  • 233
  • 301
  • Thanks for your answer! I came across a strange issue, however. The window split vertically the first time I tried, but horizontally the second time. I'm going to try again after I move my `.vimrc`, in case any of my plugins may be interfering. – void-pointer Apr 25 '13 at 23:57
  • After using manual binary search on my `.vimrc` file, I isolated the line in my `.vimrc` causing the problem: `set hidden`. – void-pointer Apr 26 '13 at 00:01
  • @void-pointer from your comment I cannot see the problem. that line I wrote in vimrc long time ago, didn't have your problem... – Kent Apr 26 '13 at 00:02
1

A very lo-tech solution:

nnoremap <leader>h :vert help <-- there's a <space> here
romainl
  • 186,200
  • 21
  • 280
  • 313