So I've created some helper functions to help work around netrw. They are some keybind simplifications that help with things like window/cursor management when opening files, where to open them, handing marked files, closing netrw when done etc.
I map them with the following in my vimrc:
augroup NetrwGroup
autocmd!
autocmd filetype netrw call NetrwMapping()
augroup END
function! NetrwMapping()
setl bufhidden=wipe | setl modifiable
nmap <buffer>x mf
nmap <buffer>. cd
nmap <buffer>C :NetrwTouch<CR>
nmap <buffer>D :NetrwDelete<CR>
nmap <buffer>h o
nmap <silent> <buffer>T :call NetrwOpenInTabs()<CR>
nmap <silent> <buffer>W :call NetrwOpenInWindows()<CR>
nmap <silent> <buffer>B :call NetrwOpenInBuffers()<CR>
" remap refresh to <c-r>, to free up <c-l>, so that it doesn't overwrite my window navigation mapping
nunmap <buffer><C-r>
nmap <buffer><C-r> <Plug>NetrwRefresh
nmap <buffer><C-l> <C-w><Right>
endfunction
Now, what I'm trying to add is an alternate to normal v
mapping. I know that normally v
is mapped to <SNR>76_NetrwSplit(5)<CR>)
. I'd like to be able to call that in my function and then do some additional things. So the mapping would be:
nmap <buffer>v :call NetrwOpenVirtSplit()<CR>
and a simple example of my function:
function! NetrwOpenVirtSplit()
normal v
" some other stuff
" move the cursor
" close netrw etc.
endfunction
Pressing v
in netrw got me this:
So if that's an easy fix, I'd like to do that and go about my life.
Alternatively, and more complicatedly, I've looked into calling <SNR>76_NetrwSplit(5)
directly, but I can't quite figure out the name spacing situation. This worked for example:
nmap <buffer>v :call <SNR>76_NetrwSplit(5)<CR>
But I know that the <SNR>76_
part depends on the script ordering and is subject to change and could break etc. I've tried to dynamically compute it via the s:SID()
function mentioned in the :h <SID>
help but don't know where to put it or how to use it. Plus, I can't really easily add additional functionality to that in an easy way like I do with the other mappings.
Note: regarding namespacing, all the above mappings/function definitions are in my vimrc and <SID>NetrwSplit()
is in autoload/netrw
map
command unless you know what you are doing so here try to make your mappingnnoremap <buffer>v :call NetrwOpenVirtSplit()<CR>
, and as a second rule of thumb when in a script always forcenormal
not to follow your mapping so in your function usenormal! v
. I think doing so has good chances to fix your recursive call.nnoremap
as well. However, for mapping netrw commands, onlynmap
seems to have any effect at all. Andnormal! v
did stop the recursive descent, however it ended up only activating visual mode; it didn't run the normal netrw command forv
unfortunately.v
in your mapping butV
and this way the mapping is not recursive anymore or 2) inNetrwOpenVirtSplit()
you replacenormal v
by a call toNetrwSplit
or to your own code which will get the file under the cursor and open it in a split. I'll try to make the second option work if I have time today :)