Difference between revisions of "How to copy path to current file/directory to system clipboard"

From Vifm Wiki
Jump to navigation Jump to search
(basename -> rootname)
(Synchronize Unix/Windows sections)
Line 17: Line 17:
 
nnoremap yn :!echo -n %c | xclip %i<cr>
 
nnoremap yn :!echo -n %c | xclip %i<cr>
  
" yank rootname
+
" yank root of current file's name into the clipboard
 
nnoremap yr :!echo -n %c:r | xclip %i<cr>
 
nnoremap yr :!echo -n %c:r | xclip %i<cr>
 
 
</source>
 
</source>
  
Line 42: Line 41:
 
" yank current filename without path to Windows clipboard
 
" yank current filename without path to Windows clipboard
 
nnoremap yn :!echo %"c %i | clip<cr>
 
nnoremap yn :!echo %"c %i | clip<cr>
 +
 +
" yank root of current file's name to Windows clipboard
 +
nnoremap yr :!echo -n %c:r | clip<cr>
 
</pre>
 
</pre>

Revision as of 13:48, 14 September 2014

This is a matter of communicating current path from Vifm to system buffer via external command.

On *nix like operating systems using xclip

Commands to copy paths to current directory and currently selected file could look like this:

" yank current directory path into the clipboard
nnoremap yd :!echo -n %d | xclip %i<cr>

" yank current file path into the clipboard
nnoremap yf :!echo -n %c:p | xclip %i<cr>

" yank current filename without path into the clipboard
nnoremap yn :!echo -n %c | xclip %i<cr>

" yank root of current file's name into the clipboard
nnoremap yr :!echo -n %c:r | xclip %i<cr>

On Windows using clip

Similar commands, but those that operate on full paths have two versions for different types of slashes.

" yank current directory path to Windows clipboard with forward slashes
nnoremap yp :!echo %"d:gs!\!/! %i | clip<cr>

" yank current directory path to Windows clipboard with backward slashes
nnoremap yP :!echo %"d %i | clip<cr>

" yank path to current file to Windows clipboard with forward slashes
nnoremap yf :!echo %"c:gs!\!/! %i | clip<cr>

" yank path to current directory to Windows clipboard with backward slashes
nnoremap yF :!echo %"c %i | clip<cr>

" yank current filename without path to Windows clipboard
nnoremap yn :!echo %"c %i | clip<cr>

" yank root of current file's name to Windows clipboard
nnoremap yr :!echo -n %c:r | clip<cr>