17

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.

Russia Must Remove Putin
  • 374,368
  • 89
  • 403
  • 331
jx12345
  • 1,650
  • 2
  • 22
  • 40

4 Answers4

26

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

user21497
  • 1,061
  • 8
  • 9
  • That looks perfect, thanks.. Could you give me a hint as to how / where to install the new version... Do I need to uninstall the existing netrw? – jx12345 May 04 '16 at 13:54
11

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.

Community
  • 1
  • 1
jx12345
  • 1,650
  • 2
  • 22
  • 40
6

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.

Jonathan.Brink
  • 23,757
  • 20
  • 73
  • 115
0

You can add this to your .vimrc, it works well with v

set splitright

By default, the netrw plugin follows your splitright setting (as indicated by its default value =&spr for the g:netrw_altv variable) when deciding where to open new windows.

I think that netrw reads the value of splitright at Vim's startup. So, setting splitright using :set splitright in a session won't affect netrw's behavior in that session.

niap
  • 1
  • 1