如何在Vim中插入没有路径的文件名

问题描述:

我知道在插入模式下,我可以使用 CTRL-R -在路径中插入文件名.

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?

您可以使用

<C-r>=expand("%:t")<CR>

请参见:help filename-modifiers.

编辑

<C-r>在插入模式下用于插入寄存器的内容. "%是包含当前文件名称的寄存器.

<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