Difference between revisions of "How to copy path to current file/directory to system clipboard"
Jump to navigation
Jump to search
On Windows using
(Add examples with xsel) |
(→On Windows using clip: Fix extra spaces) |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 9: | Line 9: | ||
<source lang="vim"> | <source lang="vim"> | ||
" yank current directory path into the clipboard | " yank current directory path into the clipboard | ||
− | nnoremap yd :!echo -n %d | xclip %i<cr> | + | nnoremap yd :!echo -n %d | xclip -selection clipboard %i<cr>:echo expand('%"d') "is yanked to clipboard"<cr> |
" yank current file path into the clipboard | " yank current file path into the clipboard | ||
− | nnoremap yf :!echo -n %c:p | xclip %i<cr> | + | nnoremap yf :!echo -n %c:p | xclip -selection clipboard %i<cr>:echo expand('%"c:p') "is yanked to clipboard"<cr> |
" yank current filename without path into the clipboard | " yank current filename without path into the clipboard | ||
− | nnoremap yn :!echo -n %c | xclip %i<cr> | + | nnoremap yn :!echo -n %c | xclip -selection clipboard %i<cr>:echo expand('%"c') "is yanked to clipboard"<cr> |
" 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 -selection clipboard %i<cr>:echo expand('%"c:r') "is yanked to clipboard"<cr> |
</source> | </source> | ||
Line 27: | Line 27: | ||
<source lang="vim"> | <source lang="vim"> | ||
− | " yank current directory path into | + | " yank current directory path into primary and selection clipboards |
− | nnoremap yd :!echo -n %d | xsel --input --primary %i && echo -n %d | xsel --clipboard --input %i<cr> | + | nnoremap yd :!echo -n %d | xsel --input --primary %i && |
+ | \ echo -n %d | xsel --clipboard --input %i<cr>:echo expand('%"d') "is yanked to clipboard"<cr> | ||
− | " yank current file path into | + | " yank current file path into primary and selection clipboards |
− | nnoremap yf :!echo -n %c:p | xsel --input --primary %i && echo -n %c:p | xsel --clipboard --input %i<cr> | + | nnoremap yf :!echo -n %c:p | xsel --input --primary %i && |
+ | \ echo -n %c:p | xsel --clipboard --input %i<cr>:echo expand('%"c:p') "is yanked to clipboard"<cr> | ||
− | " yank current filename without path into | + | " yank current filename without path into primary and selection clipboards |
− | nnoremap yn :!echo -n %c | xsel --input --primary %i && echo -n %c | xsel --clipboard --input %i<cr> | + | nnoremap yn :!echo -n %c | xsel --input --primary %i && |
+ | \ echo -n %c | xsel --clipboard --input %i<cr>:echo expand('%"c') "is yanked to clipboard"<cr> | ||
− | " yank root of current file's name into | + | " yank root of current file's name into primary and selection clipboards |
− | nnoremap yr :!echo -n %c:r | xsel --input --primary %i && echo -n %c:r | xsel --clipboard --input %i<cr> | + | nnoremap yr :!echo -n %c:r | xsel --input --primary %i && |
+ | \ echo -n %c:r | xsel --clipboard --input %i<cr>:echo expand('%"c:r') "is yanked to clipboard"<cr> | ||
</source> | </source> | ||
Line 47: | Line 51: | ||
<source lang="vim"> | <source lang="vim"> | ||
" yank current directory path into the clipboard | " yank current directory path into the clipboard | ||
− | nnoremap yd :!echo -n %d | pbcopy %i<cr> | + | nnoremap yd :!echo -n %d | pbcopy %i<cr>:echo expand('%"d') "is yanked to clipboard"<cr> |
" yank current file path into the clipboard | " yank current file path into the clipboard | ||
− | nnoremap yf :!echo -n %c:p | pbcopy %i<cr> | + | nnoremap yf :!echo -n %c:p | pbcopy %i<cr>:echo expand('%"c:p') "is yanked to clipboard"<cr> |
" yank current filename without path into the clipboard | " yank current filename without path into the clipboard | ||
− | nnoremap yn :!echo -n %c | pbcopy %i<cr> | + | nnoremap yn :!echo -n %c | pbcopy %i<cr>:echo expand('%"c') "is yanked to clipboard"<cr> |
" 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 | pbcopy %i<cr> | + | nnoremap yr :!echo -n %c:r | pbcopy %i<cr>:echo expand('%"c:r') "is yanked to clipboard"<cr> |
</source> | </source> | ||
Line 66: | Line 70: | ||
<source lang="vim"> | <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> |
" yank current directory path to Windows clipboard with backward slashes | " yank current directory path to Windows clipboard with backward slashes | ||
− | nnoremap yP :!echo %"d %i | clip<cr> | + | nnoremap yP :!echo %"d%i| clip<cr> |
" yank path to current file to Windows clipboard with forward slashes | " yank path to current file to Windows clipboard with forward slashes | ||
− | nnoremap yf :!echo %"c:gs!\!/! %i | clip<cr> | + | nnoremap yf :!echo %"c:gs!\!/!%i| clip<cr> |
" yank path to current directory to Windows clipboard with backward slashes | " yank path to current directory to Windows clipboard with backward slashes | ||
− | nnoremap yF :!echo %"c %i | clip<cr> | + | nnoremap yF :!echo %"c%i| clip<cr> |
" 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 | " yank root of current file's name to Windows clipboard | ||
− | nnoremap yr :!echo | + | nnoremap yr :!echo %"c:r%i| clip<cr> |
</source> | </source> | ||
[[Category:HOWTO]] | [[Category:HOWTO]] |
Latest revision as of 10:26, 28 April 2022
This is a matter of communicating current path from Vifm to system buffer via external command.
On *nix like operating systems using xclip[edit]
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 -selection clipboard %i<cr>:echo expand('%"d') "is yanked to clipboard"<cr>
" yank current file path into the clipboard
nnoremap yf :!echo -n %c:p | xclip -selection clipboard %i<cr>:echo expand('%"c:p') "is yanked to clipboard"<cr>
" yank current filename without path into the clipboard
nnoremap yn :!echo -n %c | xclip -selection clipboard %i<cr>:echo expand('%"c') "is yanked to clipboard"<cr>
" yank root of current file's name into the clipboard
nnoremap yr :!echo -n %c:r | xclip -selection clipboard %i<cr>:echo expand('%"c:r') "is yanked to clipboard"<cr>
On *nix like operating systems using xsel[edit]
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 primary and selection clipboards
nnoremap yd :!echo -n %d | xsel --input --primary %i &&
\ echo -n %d | xsel --clipboard --input %i<cr>:echo expand('%"d') "is yanked to clipboard"<cr>
" yank current file path into primary and selection clipboards
nnoremap yf :!echo -n %c:p | xsel --input --primary %i &&
\ echo -n %c:p | xsel --clipboard --input %i<cr>:echo expand('%"c:p') "is yanked to clipboard"<cr>
" yank current filename without path into primary and selection clipboards
nnoremap yn :!echo -n %c | xsel --input --primary %i &&
\ echo -n %c | xsel --clipboard --input %i<cr>:echo expand('%"c') "is yanked to clipboard"<cr>
" yank root of current file's name into primary and selection clipboards
nnoremap yr :!echo -n %c:r | xsel --input --primary %i &&
\ echo -n %c:r | xsel --clipboard --input %i<cr>:echo expand('%"c:r') "is yanked to clipboard"<cr>
On macOS using pbcopy[edit]
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>:echo expand('%"d') "is yanked to clipboard"<cr>
" yank current file path into the clipboard
nnoremap yf :!echo -n %c:p | pbcopy %i<cr>:echo expand('%"c:p') "is yanked to clipboard"<cr>
" yank current filename without path into the clipboard
nnoremap yn :!echo -n %c | pbcopy %i<cr>:echo expand('%"c') "is yanked to clipboard"<cr>
" yank root of current file's name into the clipboard
nnoremap yr :!echo -n %c:r | pbcopy %i<cr>:echo expand('%"c:r') "is yanked to clipboard"<cr>
On Windows using clip
[edit]
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 %"c:r%i| clip<cr>