4

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-file shows ~/symlink-to-file;
  • the bug is triggered only in shell command line; vim with :ed ~/symlink-to-dir/file shows the symlink, not the resolved target;
  • the path must be absolute: vim ~/symlink-to-dir/file triggers the bug, vim ../symlink-to-dir/file doesn'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.

phd
  • 141
  • 3
  • 3
    This probably belongs on the Vim bug tracker on GitHub – D. Ben Knoble Dec 20 '23 at 15:33
  • 1
    I added this to an existing bug report: https://github.com/vim/vim/issues/4942#issuecomment-1864917074 . Should I remove the question? – phd Dec 20 '23 at 18:12
  • 1
    Your call; assuming this might get fixed, this could help folks find the answer. It’s not off-topic AFAICT, and the up-votes indicate it’s a good question to some degree, so removing isn’t strictly necessary. – D. Ben Knoble Dec 20 '23 at 23:08

0 Answers0