Yank 文件名/Vim 中当前缓冲区的路径 [英] Yank file name / path of current buffer in Vim

查看:23
本文介绍了Yank 文件名/Vim 中当前缓冲区的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设当前缓冲区是一个打开进行编辑的文件,所以:e 不会显示E32: No file name.

Assuming the current buffer is a file open for edit, so :e does not display E32: No file name.

我想删除其中一个或全部:

I would like to yank one or all of:

  • 与状态行上显示的完全相同的文件名,例如~myfile.txt
  • 文件的完整路径,例如c:fooarmyfile.txt
  • 只是文件名,例如myfile.txt

推荐答案

TL;DR

:let @" = expand("%")>

这会将文件名复制到未命名寄存器,然后您可以使用旧的p 粘贴它.当然,您可以将其映射到密钥以便更快地使用.

this will copy the file name to the unamed register, then you can use good old p to paste it. and of course you can map this to a key for quicker use.

:nmap cp :let @" = expand("%")

您也可以将其用于完整路径

you can also use this for full path

:let @" = expand("%:p")

说明

Vim 使用未命名寄存器来存储已被删除或复制(猛拉)的文本,同样,当您粘贴时,它会从该寄存器读取文本.

Vim uses the unnamed register to store text that has been deleted or copied (yanked), likewise when you paste it reads the text from this register.

使用 let 我们可以使用 :let @" = "text" 手动将文本存储在寄存器中,但我们也可以存储表达式的结果.

Using let we can manually store text in the register using :let @" = "text" but we can also store the result of an expression.

在上面的例子中,我们使用函数 expand 来扩展通配符和关键字.在我们的示例中,我们使用 expand('%') 来扩展当前文件名.我们可以将其修改为 expand('%:p') 以获取完整的文件名.

In the above example we use the function expand which expands wildcards and keywords. in our example we use expand('%') to expand the current file name. We can modify it as expand('%:p') for the full file name.

查看:help let :help expand :help registers 详情

这篇关于Yank 文件名/Vim 中当前缓冲区的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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