Given this situation:

cd ~/temp
ln -s /var/lib/alsa alsa
cd alsa
pwd -> /home/<username>/temp/alsa

But if I open some file in the directory output of pwd, the vim statusline gives me:


How can I make it show the pwd result, and not follow the link?

I'm using:

set statusline=%F%=%m\ %y\ \%r\ %1*\ \%l\:\%c\ \%2*\ \ \%p%%\ \ 

@Gnouc's answer goes into the right direction, but you must not invoke an external command from within the statusline evaluation! This will spawn a new process on every cursor move and typed character, and drag down Vim's performance (as you've experienced).

Better split this into two parts: an :autocmd that updates a variable whenever the current buffer changes, and a very efficient consumption of that variable in the statusline itself:

set statusline=%{exists('b:actualCwd')?b:actualCwd:getcwd()}/%f%=%m\ %y\ \%r\ %1*\ \%l\:\%c\ \%2*\ \ \%p%%\ \ 
autocmd BufEnter * let b:actualCwd = system('echo -n $(pwd -L)')

You can not do this with vim directly, vim will always resolves the links to find the name of the actual file.

From :h E773:

For symbolic links Vim resolves the links to find the name of the actual file.  
The swap file name is based on that name.  Thus it doesn't matter by what name  
you edit the file, the swap file name will normally be the same.

You can use external command to get current working directory, plus %f of statusline.


set statusline=%{system('echo\ -n\ $\(pwd\ -L\)')}/%f%=%m\ %y\ \%r\ %1*\ \%l\:\%c\ \%2*\ \ \%p%%\ \ 

For more information:

:h E773
:h todo.txt
:h version7.txt
  • really nice solution, but in my vim, my cursor is slow as hell. I'll just make a function that checks if i'm in directory x, than show %f or %F. – user1101 Sep 13 '14 at 1:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.