0

Suppose I have 2 windows open, each one with its respective buffer (b1 != b2 meaning two different files), so:

w1 -> b1 w2 -> b2

If now I open netrw using Vexplore! thus having a new window w3, and I decide to open b1 (which is already opened in w1), vim re-opens the buffer b1 as expected in w3.

Is there a way to avoid this buffer duplication in netrw ?

My current netrw setup from .gvimrc is the following:

" hide netrw menu
let g:netrw_banner = 0
" tree listing
let g:netrw_liststyle = 0
" open files in new tab
let g:netrw_browse_split = 0
let g:netrw_bufsettings = 'noma nomod nu nobl nowrap ro'
let g:netrw_fastbrowse = 1
let g:netrw_list_hide = '^\./$'
let g:netrw_hide = 1
let g:netrw_dirhistmax = 0
4
  • 1
    What did you find in :help netrw?
    – romainl
    Commented Jul 19 at 15:03
  • Bookmarks. Apparently not a specific option to control the behavior I would like to have.
    – simzz
    Commented Jul 19 at 19:53
  • 1
    The buffer isn’t duplicates, FWIW; are you trying to avoid an extra window?
    – D. Ben Knoble
    Commented Jul 20 at 21:06
  • Yes, exactly. At least being able to control this behavior since sometimes having the buffer on multiple windows can be useful to have look at different areas of the code at the same time.
    – simzz
    Commented Jul 20 at 21:25

1 Answer 1

2

I'm surprised that none of the :help g:netrw_browse_split options use :sbuffer or other 'switchbuf' commands, but here's something we can try: with 'switchbuf' including something like useopen, :sbuffer <C-r><C-a><Tab> should start completing :sbuffer with the file under the cursor. If there's only one buffer named something similar, then press enter.

If you have lots of open buffers with the same name, you'll need to pick the right one (you might be able to get the netrw directory to help).

I personally use :sbuffer without switchbuf=useopen, so I would probably temporarily turn it on if I really wanted to do this. Then again, I don't mind the extra window (or I'll close it if I do).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.