How to insert the current filename into the contents in Vim

vim

After some searching, I got to know :echo @% displays the current filename in the bottom line of vim-screen.

I would like to dump the filename (with and without full path) into the contents of the file without leaving vim.

Is there any way to do this?

Best Answer

The current filename is in the "% register, so you can insert it (while in insert mode) with <c-r>%; the full path can be inserted with <c-r>=expand("%:p"). You could make a macro of it if you use it often. For more, similar tricks, see :h expand and :h "=.

Related Question