Open file in vertical split in Vim / netrw
Netrw v153 and later (May 28, 2014) gives you the :Lexplore
command, which, by default, opens a directory listing on the left hand side and opens files to the right (by pressing <cr>
).
Whilst Jonathan.Brink's answer works perfectly well, simply adding
let g:netrw_altv=1
to .vimrc also seems to do the trick...
See https://superuser.com/questions/1056929/open-file-in-vertical-split-in-vim-netrw/1062063#1062063 for more info.
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.