Autocmd doesn't trigger on symlinked directory

19 views
Skip to first unread message

Marco

unread,
Jan 7, 2021, 1:08:52 PM1/7/21
to vim...@googlegroups.com
Hi,

I want to trigger a command when a file in a particular directory is saved.
The solution discussed here work in general.

https://stackoverflow.com/questions/20419121/how-to-automatically-run-a-command-after-saving-a-file

However, I run into issues when the directory is symlinked as in
this (as of now unanswered) question:

https://vi.stackexchange.com/questions/25136/autocmd-pattern-matching-symlinked-directory

So basically the issue is that vim resolves the symlink and doesn't
trigger the autocmd. Example:

mkdir -p ~/vim-test/foo
cd vim-test
ln -s foo symlink-to-foo

" in .vimrc:
augroup ft_customhelp
au!
au BufWritePost ~/vim-test/foo/file-* echo "~/vim-test/file_in_foo_was_saved"
au BufWritePost ~/vim-test/symlink-to-foo/file-* echo "~/vim-test/file_in_symlink_to_foo_was_saved"
augroup END

vi ~/vim-test/foo/file-foo
i foo <esc>:w
→ ~/vim-test/file_in_foo_was_saved

rm ~/vim-test/file_in_foo_was_saved
vi ~/vim-test/symlink-to-foo/file-bar
i bar <esc>:w
→ ~/vim-test/file_in_foo_was_saved
# rather than ~/vim-test/file_in_symlink_to_foo_was_saved

How to trigger the autocmd reliably on symlinked directories?

Marco

Christian Brabandt

unread,
Jan 7, 2021, 1:11:06 PM1/7/21
to vim...@googlegroups.com
I believe Vim always does always resolve to the final path, so it is not
possible what you want.

Best,
Christian
--
Natur ist Mathematik unter Zwangsbedingungen, das heißt, nicht jede
Lösung die mathematisch möglich wäre wird auch realisiert.
-- Harald Lesch

Marco

unread,
Jan 7, 2021, 2:12:18 PM1/7/21
to vim...@googlegroups.com
On Thu, 7 Jan 2021 19:10:58 +0100
Christian Brabandt <cbl...@256bit.org> wrote:

> > How to trigger the autocmd reliably on symlinked directories?
>
> I believe Vim always does always resolve to the final path, so it is
> not possible what you want.

That's unfortunate. Then I'll need to run the commands manually.
Thanks for the quick reply.

Marco
Reply all
Reply to author
Forward
0 new messages