codegourmet

savory code and other culinary highlights

Vim: Yank Path of Current File

| Comments

If you have a file open, you can yank the current buffer’s path to a register using the expand command:

1
:let @" = expand("%:p")

Since I’m using the unnamed buffer as system clipboard, my vim config/alias for this is:

1
2
set clipboard=unnamed
nnoremap <silent> cp :let @*=expand("%:p")<CR>

This way, typing cp in a buffer will copy it’s file path to the vim clipboard and to the Linux X Window system’s clipboard.

By the way: have a look at the expand() command: :help expand, it’s very useful.

Source/Credits: http://stackoverflow.com/questions/916875/yank-file-name-path-of-current-buffer-in-vim

Happy Coding! – codegourmet

Comments