If I put this
augroup AU_NAME
autocmd!
autocmd CursorMoved *.cpp,*.hs echo localtime()
augroup END
autocmd! AU_NAME CursorMoved *.cpp
in my vimrc, then open a file and enter :au AU_NAME
, I see
--- Autocommands ---
AU_NAME CursorMoved
*.hs echo localtime()
i.e. the autocmd!
deletion action was only limited to *.cpp
files, and it did counteract part of what the autocmd
had targeted.
However, if the autocmd
had been autocmd CursorMoved * echo localtime()
, then the autocmd!
for *.cpp
has no effect.
I think the reason is clear: the *
pattern in autocmd Event * ...
does not expand to a comma separated (infinite) list of patterns from which autocmd! Group Event pattern
can subtract the pattern.
However, is there a way to accomplish the task?
To avoid the XY problem, I'll give a hint of what my plan is.
With this plugin I've created, and which I'm still refining, I create a popup on CursorHold
showing the whole line soft-wrapped on top of itself and some lines below (a mapping is provided to dismiss the popup). The user can pass, as an option, a string, say '*.cpp,*.html'
which I use as the pattern for the autocmd CursorHold
. The string defaults to '*'
to target all files.
However, I also want to give users a way to request that the popup is shown as soon as the cursor moves, i.e. on CursorMoved
(and still be given the same mapping to dismiss it). I would let the user pass another string to use as the pattern for this autocmd CursorMoved
.
Now it's clear that for a given file type I don't want both CursorHold
and CursorMoved
to create a popup. Indeed, if the user gives the options this way,
let g:myplugin_opts = #{ onHold: '*', onMove: '*.cpp' }
to mean that they want to show the popup on CursorHold
for every filetype except for C++ file, for which they want to show popup on CursorMoved
, I can't just use those two strings for autocmd CursorHold
and autocmd CursorMoved
respectively, because in C++ files both autocmd
s would create a popup (and since I'm providing one nnoremap
to close the popup by ID, it would close only one of the two popups).