I knew that in the insert mode i can insert the filiename with the path using CTRL-R-%.
But i'd like to insert only the filename without the path part. Is there a similar command for that?
In insert mode, type Ctrl-R then % to insert the name of the current file. In command mode (after typing a colon), type Ctrl-R then % to insert the name of the current file. The inserted name can then be edited to create a similar name.
Save this answer. Show activity on this post. ctrl + g will do it.
Note, %F will be the full path. To get a path relative to the working directory, use %f .
In normal mode press A (uppercase). Vim will be switched to insert mode, and the cursor will be moved to the end of the current line ready for input. IMO, this should be the accepted answer.
You can use
<C-r>=expand("%:t")<CR>
See :help filename-modifiers
.
Edit
<C-r>
is used in insert mode to insert the content of a register. "%
is the register that contains the name of the current file.
"=
is the expression register, it contains the result of the expression that comes after =
:
<C-r>=2+27+6<CR> --> 35
<C-r>=expand("%:t")<CR> --> file.txt
While in insert mode, you can use
CTRL-R =expand('%:t')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With