17

Is there a quick way to copy the full path of current buffer to system clip board or some register? :put=expand('%:p') then use other copy commands(like dd) works but the typing is a little long.

1

1 Answer 1

24

You can assign to the clipboard with the special + register:

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

The :p makes it an absolute path; drop it if you want the relative path.

If you want to make this easier, you could create a command, so you only have to type :CopyBuffer:

:command! CopyBuffer let @+ = expand('%:p')

and/or map it to a key:

:nnoremap <Leader>c :let @+=expand('%:p')<CR>

The post "How can I copy text to the system clipboard from Vim?" has much more information on how to interface with the system's clipboard.

:put=expand('%:p') works but the typing is a little long.

This doesn't copy the path of the buffer to the clipboard, but inserts it in the buffer...?

4
  • Thanks. I meant put into buffer then copy to clipboard or registers via other command.
    – Thomson
    Jun 24, 2015 at 17:19
  • @Thomson So you want to do 2 operations in 1 go? Put the filen name in the buffer and copy it to the operating system's clipboard? Jun 24, 2015 at 19:55
  • I just want to copy the file name of the buffer to clipboard, the previous 2 operations are an crappy workaround.
    – Thomson
    Jun 24, 2015 at 22:22
  • I loose my buffer content after Ctrl-Z :( Nov 24, 2022 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.