how to insert filename without the path in vim

匆匆过客 提交于 2019-12-10 03:56:18

问题


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?


回答1:


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



回答2:


While in insert mode, you can use

CTRL-R =expand('%:t')


来源:https://stackoverflow.com/questions/18310811/how-to-insert-filename-without-the-path-in-vim

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!