除了%您自己发现插入寄存器外,您还可以使用:edit %<Tab>。
来自:help cmdline-special:
In Ex commands, at places where a file name can be used, the following
characters have a special meaning. These can also be used in the expression
function `expand()`.
% Is replaced with the current file name. :_% c_%
因此,您可以使用例如:
:edit %.orig
编辑file.txt.orig。对于您的示例,您将键入:e ../trunk/%,按<Tab>以获得具有相对路径的文件名,并2在按之前将其删除<Enter>。
您可以在路径中添加一些修改器以对其进行修改。我发现:h它特别有用,它获取当前路径的“目录名”(或在Vim中为“ head”):
:edit file/in/a/deeply/nested/subdirectory/here.txt
:edit %:h/in_same_dir_as_above.txt
您甚至可以使用:h多次。例如:
:edit %:h:h:h/file.txt
将打开 file/in/a/deeply/file.txt
它还:p提供了完整的路径,并且在您的情况下可能会有用:输入:e %:p,按<Tab>并根据需要编辑路径。您甚至可以使用多个修饰符,例如::e %:p:h。
请参阅:help filename-modifiers完整列表。
注意:如果您愿意<Tab>,Vim会展开%。如果使用<C-d>,Vim不会展开%(但%在完成路径时会替代)。
Ctrl-r =expand('%:p')。这使用=寄存器。