0

I have the following command which defines an iabbrev:

if !snips_installed
    augroup VimLogger
        autocmd!
        autocmd Filetype vim iabbrev <buffer> log hello!!
    augroup END
endif

It works when I open the .vimrc file. However, if I change the output, for example to:

autocmd Filetype vim iabbrev <buffer> log new!

It still produces the old output. I thought the purpose of augroup is to be able to update (and cancel out old) commands, but it doesn't seem to be working. What am I doing incorrectly here, or what might the issue be here? It seems like not only do I have to refresh the vimrc, I also have to 're-do' the filetype?

:w | so % | set ft=vim

?

1

Changing the autocommand in your file doesn’t automatically change the one in memory! (It is possible to add to or clear an auto group at runtime with Ex commands, but not there way shown.) Additionally, changing the in-memory version won’t automatically change the relevant mapping or abbreviation.

So the sequence is

  1. Update the code autocommand
  2. Source the file to update the one in memory
  3. Trigger the event so the code for the event runs

To clear an entire auto-group from outside the group:

autocmd! group

(:help autocmd-remove has more targeted variants.)

To add to an auto-group from outside it (:help autocmd-define):

autocmd group event pattern ...
| improve this answer | |
  • @D -- thanks, could you please show an example of how you could do something like: add to our clear an auto group at runtime with Ex commands within the autogroup? – David542 Jun 28 at 19:34
  • @David542 done! – D. Ben Knoble Jun 28 at 20:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.