从 vim 中的当前文件获取本地路径

Fetch local path from current file in vim

我的文件在远程目录中。当我使用 Vim 中的 % 获取文件名时,如 here 所述。我获得了一个远程路径,例如\domain\path\anotherpath\。我使用的某个命令!<command> %无法处理此远程路径。

在另一个程序和 Windows 资源管理器中,我看到本地路径是 G:\path\anotherpath

现在如何在 Vim 中获取此本地路径?

两个选项,如果您的 shellslash 始终单独留在 windows、

exe '!dir '.shellescape(expand('%:p'))

!dir "%"    " may also work

应该做。

但是,如果您的 shellslash 选项已被修改,您必须确保在 windows 上将其设置为 noshellslash,或者使用来自我的 [=] 17=]

exe '!dir '.lh#system#FixPathName(expand('%:p'))

注意:如果您想将命令应用于当前文件所在的目录,expand() 修饰符将需要 :h -> expand('%:p:h').