Autocmd doesn't trigger on symlinked directory

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Autocmd doesn't trigger on symlinked directory

Marco-4
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20210107164151.0d569d3a%40homerow.
Reply | Threaded
Open this post in threaded view
|

Re: Autocmd doesn't trigger on symlinked directory

Christian Brabandt

On Do, 07 Jan 2021, Marco wrote:

> 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?

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

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20210107181058.GA2910256%40256bit.org.
Reply | Threaded
Open this post in threaded view
|

Re: Autocmd doesn't trigger on symlinked directory

Marco-4
On Thu, 7 Jan 2021 19:10:58 +0100
Christian Brabandt <[hidden email]> 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

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20210107200836.1fafe94b%40homerow.