简体   繁体   中英

Copy the current file name to the clipboard

如何从OS X上的Vim将当前缓冲区的文件名发送到剪贴板。

does this help you?

:let @+=expand('%:p')

if you need do this often, create a map.

This will do it

:!echo -n % | pbcopy
  • % stands for the current buffer's filename in Vim.
  • echo -n % will print the current file name without a newline char at the end.
  • | will pipe the output of the above expression to the following command
  • pbcopy adds stuff to the clopboard on OS X.

You can map this to a handy shortcut by putting this in your .vimrc

nnoremap <leader>f :!echo -n % \| pbcopy<cr>

I use the following in my ~/.vimrc file:

" yank a register into another register
" ["x]yr{reg}
nnoremap <silent> yr :call setreg(v:register, getreg(nr2char(getchar())))<cr>

This allows me to copy a register to another register. I typically use this to copy the @% register to the unnamed or system clipboard. eg "+yr% . However I have found it useful to copy the @. and @: on rare occasion.

On OSX. To copy the fullpath to the clipboard, you can use :!echo %:p | pbcopy :!echo %:p | pbcopy Then you can paste it anywhere (including vim)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM