Closed JakeElder closed 3 years ago
This plugin adds the - key binding which opens netrw in the current pane, with the currently open file selected.
-
I find I often want to perform this operation, but close the buffer I came from. I've looked through the source to attempt it and am struggling.
IE, if I know I'm finished working on a file, then navigate to another from the path of that file.
I lifted the s:seek function from this plugin and tried some variations using it but I'm not doing well..
s:seek
" <leader>u Goes to current directory and closes buffer " Taken from vim-vinegar function! s:seek(file) abort if get(b:, 'netrw_liststyle') == 2 let pattern = '\%(^\|\s\+\)\zs'.escape(a:file, '.*[]~\').'[/*|@=]\=\%($\|\s\+\)' else let pattern = '^\%(| \)*'.escape(a:file, '.*[]~\').'[/*|@=]\=\%($\|\t\)' endif call search(pattern, 'wc') return pattern endfunction function! s:replace_with_netrw() let dir = expand('%:p:h') execute "enew" execute "Explore " . dir call s:seek(expand('#:t')) execute "bd #" endfunction map <leader>u :call <SID>replace_with_netrw()<cr>
Can anyone help?
+1
If I was going to attempt this, I would let bufnr = bufnr(''), navigate to the new location, and exe bufnr 'bdelete'. I would not rely on # as sometimes a hidden keepalt can screw you.
let bufnr = bufnr('')
exe bufnr 'bdelete'
#
keepalt
This plugin adds the
-
key binding which opens netrw in the current pane, with the currently open file selected.I find I often want to perform this operation, but close the buffer I came from. I've looked through the source to attempt it and am struggling.
IE, if I know I'm finished working on a file, then navigate to another from the path of that file.
I lifted the
s:seek
function from this plugin and tried some variations using it but I'm not doing well..Can anyone help?