本文介绍了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.

我想拉一个或全部:

  • 文件名与状态行上显示的完全相同,例如~\myfile.txt
  • 文件的完整路径,例如c:\foo\bar\myfile.txt
  • 只是文件名,例如myfile.txt
  • The file name exactly as show on the status line, e.g. ~\myfile.txt
  • A full path to the file, e.g. c:\foo\bar\myfile.txt
  • Just the file name, e.g. myfile.txt

推荐答案

TL; DR

>

这会将文件名复制到 unmed寄存器,然后您可以使用较旧的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("%")<cr>

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

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

See :help let :help expand :help registers for details

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

07-24 08:27