vim ~/symlink-to-dir/file resolves the symlink and shows me ~/real-dir/file in the status line and in echo expand('%'). After a few hours of experiments I found the problem is reproducible.
The conditions for the bug are (~/.vim/ and ~/.vimrc are absent or empty):
- the symlink must be a link to a directory; direct link to a file doesn't trigger the bug;
vim ~/symlink-to-fileshows~/symlink-to-file; - the bug is triggered only in shell command line;
vimwith:ed ~/symlink-to-dir/fileshows the symlink, not the resolved target; - the path must be absolute:
vim ~/symlink-to-dir/filetriggers the bug,vim ../symlink-to-dir/filedoesn't.
I reproduced the bug with different versions of vim on different Linux systems. I reproduced the bug with vim 7.4 on CentOS with absent ~/.vim/ and ~/.vimrc. I triggered the bug with vim 9.0 at Debian 12.4 with additional condition: :set laststatus=2 in ~/.vimrc; absent laststatus or other values (0 or 1) don't trigger the bug.
Can anybody reproduce the bug? Could you suggest any workaround to prevent vim to resolve the symlink (without changing/removing statusline=2)? Should I report this as a bug?
A script to reproduce the bug:
#! /bin/sh
set -e
cd "$HOME"
trap 'set +e; rm -rf .vim .vimrc test-dir test-syml;
mv .vim-backup .vim; mv .vimrc-backup .vimrc' EXIT HUP INT QUIT TERM
mv .vim .vim-backup
mv .vimrc .vimrc-backup
rm -rf test-dir test-syml
echo set laststatus=2 > .vimrc
mkdir test-dir
echo Test >test-dir/test-file
ln -s test-dir test-syml
vim -c "echo expand('%')" "$HOME"/test-syml/test-file
Expected output (both in the status line and from expand('%')) in vim: ~/test-syml/test-file; the actual output is ~/test-dir/test-file.