9

When using :help, it splits the window horizontally and opens the help in the top window. I then need to use ^w L to move the help window to the right. Same thing if use ^w f to open a file under the cursor, the window is split horizontally and the file is opened in the top window.

Is there a way to have these commands split the window vertically instead?

4 Answers 4

5

Vim provides these commands:

:vert[ical] {cmd}
    Execute {cmd}.  If it contains a command that splits a window,
    it will be split vertically.

:[count]winc[md] {arg}
    Like executing CTRL-W [count] {arg}.

Therefore:

  • To open a vertical help window type :vert help
  • To edit the file name under cursor in a new vertical split type :vert winc f
1

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).

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

One solution to this problem is to add commands. I like terse commands so I named so but you can name as you wish.

"
" -narg: the number of arguments to the command
" -complete: enables arguments completion with `help` subjects
" <args>: a placeholder that will be replaced by an argument to the command
" 

" :Hv to open vertically
command -narg=1 -complete=help H vert help <args>
" :Ht to open in a new tab
command -narg=1 -complete=help Hh tab help <args>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .