Search code examples
vimnetrw

how to make netrw in vim work like solution explorer in visual studio


okay, i will make this more clear here.. say i have the directory listing in a vertical split window, along with the file i'm editing..

i can go from one split to the other using Ctrl+w and open files in the file listing using netrw plugin in four ways.. using return key, v, o, t..

with return key, it opens in the current(netrw) split window.. with v, it creates a new vertical split..(same with o(horizontal split), t(new tab))

but i want the file to be opened in the other split that is already there, where i do all the editing..instead of opening a new split.. i hope my question is clear.. say by typing a command, the highlighted file will open in the editing split instead of the netrw split.. there must be some easy solution to this.. or can someone tell me the best way to use netrw.. i will try to adapt..


Solution

  • The answer is in the doc: :h netrw. As usual.

    You are looking for P:

    To edit a file or directory in the previously used (last accessed) window (see
    :he CTRL-W_p), press a "P".  If there's only one window, then the one window
    will be horizontally split (above/below splitting is controlled by
    g:netrw_alto, and its initial size is controlled by g:netrw_winsize).
    
    If there's more than one window, the previous window will be re-used on
    the selected file/directory.  If the previous window's associated buffer
    has been modified, and there's only one window with that buffer, then
    the user will be asked if s/he wishes to save the buffer first (yes,
    no, or cancel).