in VIM, How to set the initial window size via file browser?

Actually the split size is not relative to netrw, it's the default size vim sets for newly created splits, so if you want to resize the actual split which is in you case the navigator (netrw) you can use this commend:

:vertical resize 30

The new window should take half of the height or half of the width of the current window which can give you small windows pretty quickly.

The option that defines that proportion can be found in :help netrw:

let g:netrw_winsize = 75

Note that using this method will make any further split even smaller than before:

let g:netrw_winsize = 50 (default)
|-netrw--------------------------------------------|
|-netrw------------------|-file--------------------|
|-netrw------|-file------|-file--------------------|

let g:netrw_winsize = 75
|-netrw--------------------------------------------|
|-netrw------|-file--------------------------------|
|-netrw|-file|-file--------------------------------|

The "problem", here is that netrw splits its own window, not the previous window.

Netrw can be used to open the file under the cursor in the current window, in a split window or in another tab but the way it splits its own window makes it hard to use it the way you want. AFAIK, the most common usage is:

  1. open netrw with :Ex,
  2. navigate,
  3. hit <CR> to open the file under the cursor in the current window,
  4. edit,
  5. re-open netrw in its latest state with :Rex (for Peter Rincker),
  6. GOTO 2

An alternative is to use :Vex to open netrw in a vertical split and use P to open the file in the previous window.

I'm afraid Netrw is not really designed to work like what you seem to want it to work. IMO, netrw is more like an "open…" dialog than the kind of file explorer pane you can see in most editors/IDEs. I'd suggest you either get used to it or try NERDTree which has only a subset of netrw's features but is designed to be more like those file explorer panes.


There is :Lex now to open a left explorer. You can place let g:netrw_winsize=30 in your vimrc file to keep the explorer small.

Tags:

Vim