有符号链接时获取 VIM 中的逻辑路径 [英] Getting the logical path in VIM when there's a symlink

查看:16
本文介绍了有符号链接时获取 VIM 中的逻辑路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下设置:

mkdir /1
mkdir /1/2
mkdir /1/2/3
ln -s /1/2/3 /1/3

如果我做cd/1/3,然后pwd,我得到/1/3.如果我使用 pwd -P,我可以得到 /1/2/3pwd -L 来强制 /1/3.

If I do cd /1/3, and then pwd, I get /1/3. If I use pwd -P, I can get /1/2/3, or pwd -L to force /1/3.

在 VIM 中,我正在寻找一种获取 /1/3 的方法.
如果我在 /1/3/foo.txt 中打开一个文件,我使用类似 fnamemodify(bufname(winbufnr(0)), ':p:h'),返回/1/2/3.
我怎么能告诉它给我与 pwd 相同的目录?

In VIM, I'm looking for a way to get the /1/3.
If I open a file in /1/3/foo.txt, and I use something like fnamemodify(bufname(winbufnr(0)), ':p:h'), it returns /1/2/3.
How can I tell it to give me the same directory that pwd would give?

推荐答案

看来你不能,只能通过 system('pwd -L').根据vim_userrelmlist Vim 现在会自动解析符号链接.

It appears you can't, other than via system('pwd -L'). According to the vim_use mailing list Vim automatically resolves symlinks nowadays.

查看:h E773 周围的文字以了解基本原理;如果 Vim 使用符号链接而不是解析文件名,则有可能在两个缓冲区中以两个不同的名称打开同一个文件,并且 Vim 会在试图找出交换文件的位置时感到困惑.另见:h version7.txt:

See the text around :h E773 for rationale; if Vim went by symlinks instead of resolved filename, it'd be possible to have the same file open in two buffers under two different names, and Vim would become confused trying to figure out where the swap file should be. See also in :h version7.txt:

Unix:当通过符号链接编辑文件时,交换文件将使用名称的符号链接.现在使用实际文件的名称,以便编辑相同检测到文件两次.

Unix: When editing a file through a symlink the swap file would use the name of the symlink. Now use the name of the actual file, so that editing the same file twice is detected.

这篇关于有符号链接时获取 VIM 中的逻辑路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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