1

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.

2

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")
endfun

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)
    endif
    execute 'normal!' (b:netrw_liststyle == netrw#Expose('WIDELIST') ? 'W' : 'j')
    return ''
endfunction
let g:Netrw_UserMaps = [
\   ['+', 'NetrwBufAdd']
\]

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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