Search code examples
vimautocmd

How to get the Help window to always open in the same position?


I do this for opening help pages in vertical window:

cabbrev help vert botright help

this way, it is ok, but a bit disturbing, and it is spamming my :history a bit too. I would like to get Vim to not expand this, just run the command. So when I write :help topic I want it to not expanded, but to run the command :vert botright help topic I tried with

cabbrev <silent> help vert botright help

but it doesn't work.

Is it possible to do at all?


Solution

  • I found the perfect solution based on this e-mail: http://vim.1045645.n5.nabble.com/Horizontal-layout-by-default-td1164876.html#a1164886
    So if you want help windows on the right, do this:

    autocmd FileType help :wincmd H
    

    this puts the 'help' type windows immediately to the right just like CTRL-W H. See :h CTRL-W_H in vim.
    The small problem with it if you have the hidden option enabled, just closing the window with :q doesn't unload the help window buffer, and if you want to open it again, it will not trigger the FileType event for some reason (why?), so if you use :set hidden you need to:

    autocmd FileType help set bufhidden=unload
    

    to get help windows unload, which is the default behavior anyway.