Konstantin
Konstantin

Reputation: 25329

Opening a file from netrw in current window

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.

Upvotes: 1

Views: 2495

Answers (1)

Ingo Karkat
Ingo Karkat

Reputation: 172500

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

Upvotes: 2

Related Questions