如何在Vim中插入没有路径的文件名 [英] how to insert filename without the path in vim

查看:97
本文介绍了如何在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

这篇关于如何在Vim中插入没有路径的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆