我使用的是 Mac 和 MacVim 7.3。
我有一个符号链接(symbolic link) ~/some/symlink,它是指向真实文件 ~/some/actual_file 的链接。
当我“vim ~/some/symlink”时,它会在 vim 中调出该文件,并且 vim 的状态行显示名称为 ~/some/symlink,这是有道理的。
如何从 vim 中获取“真实”文件 ~/some/actual_file 的完整路径?我希望 vim 状态行显示 ~/some/actual_file 而不是 ~/some/symlink。
鉴于其帮助描述(粘贴在下面),我预计 vim 函数resolve() 会起作用,但是resolve("~/some/symlink") 返回~/some/symlink,所以这没有帮助。
我错过了什么?谢谢!
resolve({filename}) *resolve()* *E655*
On MS-Windows, when {filename} is a shortcut (a .lnk file),
returns the path the shortcut points to in a simplified form.
On Unix, repeat resolving symbolic links in all path
components of {filename} and return the simplified result.
To cope with link cycles, resolving of symbolic links is
stopped after 100 iterations.
On other systems, return the simplified {filename}.
最佳答案
您的问题是“~”,它实际上并不是文件名的一部分,而是您的主目录的简写。您可以使用 expand()
,然后使用 resolve()
。例如:
:echo resolve(expand("~/some/symlink"))
expand()
还将扩展环境变量等内容(例如:$HOME
、$VIMRUNTIME
)。
关于vim - 如何在vim中将符号链接(symbolic link)扩展为文件名的完整路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5794611/