views:

208

answers:

1

I have the following setup:

mkdir /1
mkdir /1/2
mkdir /1/2/3
ln -s /1/2/3 /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.

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?

+1  A: 

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

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: 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.

Brian Carper
Ok, followup question. If I run vim using "vim 1/3/foo.txt", how can I use system('pwd -L')? If I change to the directory using cd %:p:h I've already jumped into the symlink /1/2/3/
Mikeage
Yeah if you :cd into the directory, I don't know if there's anything you can do at that point. You can do something horrible like system('cd "' . expand('%:h') . '"; pwd -L') before :cd'ing Vim itself but not sure what you're using this for, it may not be enough.
Brian Carper