Highlight arguments in function body in vim

This is much harder than it sounds, and borderline-impossible with the vimscript API as it stands, because you don’t just need to parse the file; if you want it to work well, you need to parse the file incrementally. That’s why regular syntax files are limited to what you can do with regexes – when you change a few characters, vim can figure out what’s changed in the syntax highlighting, without redoing the whole file.

The vim syntax highlighter is limited to dealing with regexes, but if you’re hellbent on doing this, you can roll your own parser in vimscript, and have it generate a buffer-local syntax that refers to tokens in the file by line and column, using the \%l and \%c atoms in a regex. This would have to be rerun after every change. Unfortunately there’s no autocmd for “file changed”, but there is the CursorHold autocmd, which runs when you’ve been idle for a configurable duration.

Leave a Comment