I'd like to add the file to the buffer list without changing the currently active netrw window. I'd also love to make this the default behaviour for netrw. Any advice? I've searched around and looked through the netrw help but can't find a solution.

1 Answer 1


The netrw plugin provides functionality to set up user-specific mappings, cp. :help netrw-usermaps. Unfortunately, when I tried this, I found the mentioned netrw#Call() function defective.

I've sent the following patch to its author:

--- autoload/netrw.vim.orig 2016-11-18 14:28:34.647159594 +0100
+++ autoload/netrw.vim  2017-01-12 10:42:07.097512428 +0100
@@ -11013,11 +11015,7 @@ fun! netrw#Access(ilist)
" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
fun! netrw#Call(funcname,...)
"  call Dfunc("netrw#Call(funcname<".a:funcname.">,".string(a:000).")")
-  if a:0 > 0
-   exe "call s:".a:funcname."(".string(a:000).")"
-  else
-   exe "call s:".a:funcname."()"
-  endif
+  return call("s:".a:funcname, a:000)
"  call Dret("netrw#Call")

With that fix, I was able to implement a + user mapping to do what you've asked for:

" +                     Add the current file to the buffer list, and go to the
"                       next file entry.
function! NetrwBufAdd( isLocal )
    let l:filespec = netrw#Call('NetrwFile', netrw#Call('NetrwGetWord'))
    if filereadable(l:filespec)
        execute 'badd' ingo#compat#fnameescape(l:filespec)
    execute 'normal!' (b:netrw_liststyle == netrw#Expose('WIDELIST') ? 'W' : 'j')
    return ''
let g:Netrw_UserMaps = [
\   ['+', 'NetrwBufAdd']

Overriding the default behavior should be a simple addition of ['<CR>', 'NetrwBufAdd'] to the above list.

  • (the patch is merged now.) Is there any difference between using Netrw_UserMaps and ~/.vim/after/ftplugin/netrw.vim (as seen in vi.stackexchange.com/questions/4552/… ?
    – user202729
    Commented Sep 21, 2021 at 8:15
  • @user202729 The filetype location uses the fact that the plugin sets the filetype of its scratch buffer to netrw, whereas the config variable is a custom extension point provided by the plugin itself. In practice, it likely doesn't matter much which one you use. Commented Sep 21, 2021 at 19:34

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.