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.
Asked
Active
Viewed 9,636 times
18
Thomson
- 852
- 8
- 17
-
To any register: http://stackoverflow.com/questions/916875/yank-file-name-path-of-current-buffer-in-vim – Ciro Santilli OurBigBook.com Oct 20 '15 at 08:56
1 Answers
28
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...?
Martin Tournoij
- 62,054
- 25
- 192
- 271
-
Thanks. I meant put into buffer then copy to clipboard or registers via other command. – Thomson Jun 24 '15 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? – Martin Tournoij Jun 24 '15 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 '15 at 22:22