1

I have this in my ~/.vimrc file

" open files from netrw in a previous window
let g:netrw_browse_split = 4
" tree-like listing of directories in netrw
let g:netrw_liststyle = 3
" set width of 25% of current window width
let g:netrw_winsize = 25
"

It allows me to use netrw as a project drawer via :Vexplore. Pressing enter on a filename opens this file in a previous window.

However, sometimes I start vim with vim . and see netrw right away. Now, if I press <cr> on any filename netrw will open a new split with that file, but I would like it to open the file in the current window. I am ok with using a different key to open files in current window, I just failed to find such key in netrw docs.

Konstantin
  • 24,271
  • 5
  • 48
  • 65
  • There's no built-in way to do this, but you could do something with `autocmd BufEnter` to detect if netrw is the only open window and temporarily toggle the value of `g:netrw_browse_split`, which I'll leave to you or someone else to implement. Or go read [this VimCasts blog post](http://vimcasts.org/blog/2013/01/oil-and-vinegar-split-windows-and-project-drawer/), install [vim-vinegar](https://github.com/tpope/vim-vinegar), and break yourself free from the evil clutches of the project drawer. – Jim Stewart Nov 23 '16 at 19:50

1 Answers1

2

You can detect this condition (opening Vim with the current directory) in your ~/.vimrc, and adapt the netrw configuration accordingly:

" open files from netrw in a previous window, unless we're opening the current dir
if argv(0) ==# '.'
    let g:netrw_browse_split = 0
else
    let g:netrw_browse_split = 4
endif
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324