Domanda

How can I send the current buffer's filename to the clipboard from Vim on OS X.

È stato utile?

Soluzione

does this help you?

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

if you need do this often, create a map.

Altri suggerimenti

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. e.g. "+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 Then you can paste it anywhere (including vim)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top