Difference between revisions of "How to copy path to current file/directory to system clipboard"
Jump to navigation
Jump to search
On Windows using
Ngriffin7a (talk | contribs) |
(Add examples with xsel) |
||
Line 19: | Line 19: | ||
" yank root of current file's name into the clipboard | " 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> | ||
+ | |||
+ | === On *nix like operating systems using [http://www.vergenet.net/~conrad/software/xsel/ xsel] === | ||
+ | |||
+ | Commands to copy paths to current directory and currently selected file into | ||
+ | both primary and selection clipboards could look like this: | ||
+ | |||
+ | <source lang="vim"> | ||
+ | " yank current directory path into the clipboard | ||
+ | nnoremap yd :!echo -n %d | xsel --input --primary %i && echo -n %d | xsel --clipboard --input %i<cr> | ||
+ | |||
+ | " yank current file path into the clipboard | ||
+ | nnoremap yf :!echo -n %c:p | xsel --input --primary %i && echo -n %c:p | xsel --clipboard --input %i<cr> | ||
+ | |||
+ | " yank current filename without path into the clipboard | ||
+ | nnoremap yn :!echo -n %c | xsel --input --primary %i && echo -n %c | xsel --clipboard --input %i<cr> | ||
+ | |||
+ | " yank root of current file's name into the clipboard | ||
+ | nnoremap yr :!echo -n %c:r | xsel --input --primary %i && echo -n %c:r | xsel --clipboard --input %i<cr> | ||
</source> | </source> | ||
Line 45: | Line 64: | ||
different types of slashes. | different types of slashes. | ||
− | < | + | <source lang="vim"> |
" yank current directory path to Windows clipboard with forward slashes | " yank current directory path to Windows clipboard with forward slashes | ||
nnoremap yp :!echo %"d:gs!\!/! %i | clip<cr> | nnoremap yp :!echo %"d:gs!\!/! %i | clip<cr> | ||
Line 63: | Line 82: | ||
" yank root of current file's name to Windows clipboard | " yank root of current file's name to Windows clipboard | ||
nnoremap yr :!echo -n %c:r | clip<cr> | nnoremap yr :!echo -n %c:r | clip<cr> | ||
− | </ | + | </source> |
[[Category:HOWTO]] | [[Category:HOWTO]] |
Revision as of 14:22, 26 November 2018
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 *nix like operating systems using xsel
Commands to copy paths to current directory and currently selected file into both primary and selection clipboards could look like this:
" yank current directory path into the clipboard
nnoremap yd :!echo -n %d | xsel --input --primary %i && echo -n %d | xsel --clipboard --input %i<cr>
" yank current file path into the clipboard
nnoremap yf :!echo -n %c:p | xsel --input --primary %i && echo -n %c:p | xsel --clipboard --input %i<cr>
" yank current filename without path into the clipboard
nnoremap yn :!echo -n %c | xsel --input --primary %i && echo -n %c | xsel --clipboard --input %i<cr>
" yank root of current file's name into the clipboard
nnoremap yr :!echo -n %c:r | xsel --input --primary %i && echo -n %c:r | xsel --clipboard --input %i<cr>
On macOS using pbcopy
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 | pbcopy %i<cr>
" yank current file path into the clipboard
nnoremap yf :!echo -n %c:p | pbcopy %i<cr>
" yank current filename without path into the clipboard
nnoremap yn :!echo -n %c | pbcopy %i<cr>
" yank root of current file's name into the clipboard
nnoremap yr :!echo -n %c:r | pbcopy %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>