Closed PabloScolpino closed 1 year ago
I have not found how to interpolate a variable with event names into autocmd, I don't know if this is possible or not
You can do this with execute
of a string, and substitute a variable into the string, like:
let term_open_event = (has('nvim') ? 'TermOpen' : 'TerminalOpen')
exe 'autocmd BufRead,BufNew,FileType,' term_open_event '* if ShouldMatchWhitespace() | match ExtraWhitespace /\\\@<![\u3000[:space:]]\+$/ | else | match ExtraWhitespace /^^/ | endif'
Both your patch and the above syntax work for me in Vim 8.2.4919 and Neovim 0.8.3
Yours keeps the syntax highlighting of the autocmd which is nice.
However, it means the autocmd
is repeated in the source twice, so future changes to the autocmd
would need be manually done on both lines.
I think it's likely a future person will make the mistake of updating one autocmd
but not the other.
So it's probably better to use the syntax with exe
of a built autocmd
string with term_open_event
variable.
Thanks for the feedback and explanation. Yes, I agree with the duplication being a likely landmine, that's what I was referring to with this "not being elegant".
I'll rework this to incorporate your suggestion and test on both editors.
Can this fix be merged in the meantime, and explore cleaner solutions later? It would be super helpful to us NeoVim users 🙂
If Pablo isn't able to follow up, I'm happy to send a PR.
Seems Pablo isn't responsive, I created PR to fix this here https://github.com/bronson/vim-trailing-whitespace/pull/30
Superseeded by PR #30 sorry for pacing out.
autocmd
does not support event patternsI have not found how to interpolate a variable with event names into autocmd, I don't know if this is possible or not