Thursday, January 7, 2021

Autocmd doesn't trigger on symlinked directory

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

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20210107164151.0d569d3a%40homerow.

No comments: