If I'm reading the acro
manual correctly, you have to define all acronyms in the preamble with \DeclareAcronym{abc}{properties}
; if that's not correct you can adapt the code below to use \ac{}
and others). Therefore, you could adopt the following strategy which will work independent of folding status, unlike using a macro:
- Write a function that reads your tex file and extracts all of the acronynm ids. Then add these to the internal word list which won't pollute your spellfile.
- Use an autocmd to execute this, I would suggest on
BufEnter
and BufWritePost
is probably sufficient).
For example, in ftplugin/tex.vim
:
function! SpellAddAcronyms()
let l:lines = getline(1, "$")
call filter(l:lines, {_, v -> match(v, '\\DeclareAcronym{') > -1})
call map(l:lines, {_, v -> matchstr(v, '\\DeclareAcronym{[^}]*}')[16:-2]})
for l:id in l:lines
silent execute ":spellgood! " . l:id
endfor
endfunction
augroup SpellAddAcronyms
autocmd! * <buffer>
autocmd BufEnter,BufWritePost <buffer> call SpellAddAcronyms()
augroup END
I use this strategy to add citekeys to the internal word list which otherwise get flagged as spelling errors.
zg
?@
, modify the register content to invoke itself at the end, then run the infinite loop until it stops when it can't find the acronym command (or one of its many variations ala regular expression). It's hazardous, though. There could be unintended side-effects which I wouldn't see except when the report is reviewed (by others).spell
's word list file, then submit the latter to a unix sort and uniquification command. There's also no chance of issuingzg
orzG
on a mistyped acronym label. I was hoping there was a way to make Vim ignore labels within curly braces, like it does for\cite{}
,\label{}
, and variations of\ref{}
..add
file; you also have to update the.spl
file (whichzg
does automatically). Either way, you could use something like%s/\v\\(ac|acs|acl|acp|acpl|Ac)\{\zs[^}]*\ze\}/\=/
if you can fit it into a single-expression; otherwise I think you'll have to write a while-loop withsearch()
. That's fair re: the hazard though. You might be able to tell syntax to ignore spelling (:help :syn-spell
)