Search code examples
vimnetrw

Open file in vertical split in Vim / netrw


If I open vim with vim . netrw provides me with a nice list of the files and directories in the current directory.

If I open a file using v the file opens in a very narrow split down the left hand side of the screen and the directory listing remains open in a wide split on the right hand side of the screen.

Ideally I'd like it to have the opposite effect, that is, to show the directory listing in a narrow split on the left hand side of the screen and show the file in a wide split on the right hand side of the screen.


Solution

  • I'm sure this could be improved upon you can write a custom mapping that target's the netrw filetype.

    Stick this in your .vimrc:

    " open file vertically to the right
    augroup netrw_mappings
        autocmd!
        autocmd filetype netrw call Netrw_mappings()
    augroup END
    function! OpenToRight()
      :rightbelow vnew
      :wincmd p
      :normal P
    endfunction
    function! Netrw_mappings()
        noremap V :call OpenToRight()<cr>
    endfunction
    

    The only thing is that you need to use V rather than v. For some reason I was unable to override netrw's v command, but using the capital version seems better anyway since it's not overriding a default.