How do I copy the current file's path into the system clipboard from Vim?
Answer
:let @+=@%
Explanation
The % register always holds the name of the current file (as a relative path). The + register maps to the system clipboard. Combining them with :let @+=@% transfers the filename directly to your clipboard so you can paste it outside of Vim.
How it works
@%reads the contents of the%register — the current file's relative path.@+is the system clipboard register (*is the primary selection on X11/Wayland;+is the clipboard).:let @+=@%assigns one register's contents to another — no yanking or visual selection needed.
Example
While editing src/utils/helpers.go, running:
:let @+=@%
Places src/utils/helpers.go in the system clipboard. You can now paste it in your terminal or browser.
To get the full absolute path instead:
:let @+=expand('%:p')
To get just the filename without directory:
:let @+=expand('%:t')
Tips
:let @"=@%copies to the unnamed register so you can paste inside Vim withp.- In Insert mode,
<C-r>%inserts the filename directly at the cursor — no clipboard involved. - Add a mapping for quick access:
nnoremap <leader>cf :let @+=expand('%:p')<CR>.