Is it possible to copy the absolute filepath of the file under the cursor in Netrw?


You can select the file under cursor through visual block mode, like Ctrl+V, then press $ and then a j and then a y.

Now, in command line mode, Type

:echo @%.@"

This will show the full path of the file under cursor.

You can also map it to a key, Like

:map \f ^<C-V>$jy:echo @%.@"<CR>

Now, you can press \f while the cursor is on a file and it will print it's full path in command line.

  • What if I am in TreeListing mode? – Niraj Gupta Jun 16 '16 at 4:06
  • Is it not working there? – SibiCoder Jun 16 '16 at 5:28
  • that does not seem to work reliably. – Christian Brabandt Jul 20 '16 at 7:22

This does not seem to be possible out of the box. Here is a small patch, that should do what you want:

diff --git a/runtime/autoload/netrw.vim b/runtime/autoload/netrw.vim
index de85844..c18d85d 100644
--- a/runtime/autoload/netrw.vim
+++ b/runtime/autoload/netrw.vim
@@ -6052,6 +6052,7 @@ fun! s:NetrwMaps(islocal)
nnoremap <buffer> <silent> <nowait> v       :call <SID>NetrwSplit(5)<cr>
nnoremap <buffer> <silent> <nowait> x       :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
nnoremap <buffer> <silent> <nowait> X       :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
+   nnoremap <buffer> <silent> <nowait> _        :call setreg(v:register, get(b:, 'current_dir', getcwd()). '/'. <SID>NetrwGetWord())<cr>
"   " local insert-mode maps
"   inoremap <buffer> <silent> <nowait> a      <c-o>:call <SID>NetrwHide(1)<cr>
"   inoremap <buffer> <silent> <nowait> c      <c-o>:exe "NetrwKeepj lcd ".fnameescape(b:netrw_curdir)<cr>

Using this, you can copy a file path using the _ key

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.