Last Updated: June 24, 2016
·
562
· ryrych

Tab completion when opening files in Vim

Press :edit %<Tab> to expand the file path relative to current window.
To expand the path, without the filename, use :edit %:h<Tab> instead.
For full, absolute path expansion use: :edit %:p<Tab>.

Sometimes it can be useful to copy the absolute path of the file to open / operate on it somewhere else. I use most when I’m opening another Vim window in a separate display. As the path is copied into system buffer, opening the file is as simple as typing :e ⌘<kbd>v</kbd>.

noremap <silent> <F4> :let @+=expand("%:p")<CR>