Skip to content

runtime(vim): Update syntax, contain Ex commands#19331

Draft
dkearns wants to merge 1 commit into
vim:masterfrom
dkearns:runtime-vim-syntax-contained-commands
Draft

runtime(vim): Update syntax, contain Ex commands#19331
dkearns wants to merge 1 commit into
vim:masterfrom
dkearns:runtime-vim-syntax-contained-commands

Conversation

@dkearns

@dkearns dkearns commented Feb 4, 2026

Copy link
Copy Markdown
Contributor
  • Contain Ex commands to valid syntactic contexts.
  • Add full address (:range) matching.
  • Match :Next, :Print, :X, :&, :~, :>, :<, :# and := commands.
  • Full matching of :global and :append commands.

Fixes:

@dkearns dkearns changed the title runtime(vim): Contain Ex commands to start of line, after : or | and subcommand contexts runtime(vim): Update syntax, contain Ex commands Feb 4, 2026
@dkearns dkearns force-pushed the runtime-vim-syntax-contained-commands branch 8 times, most recently from f796619 to 7f22036 Compare February 4, 2026 18:46
@mao-yining

Copy link
Copy Markdown
Contributor

Can this pr fix this problem?
In vim9 call and let are not necessary, but everything behind silent and silent! are highlight as command, even function or g:thing, while exe and echo 's highlight are well.

@dkearns dkearns force-pushed the runtime-vim-syntax-contained-commands branch from 5a7def7 to 4c0eba6 Compare February 7, 2026 12:07
@dkearns dkearns force-pushed the runtime-vim-syntax-contained-commands branch 2 times, most recently from 000a492 to 29d0fa6 Compare March 1, 2026 17:10
@dkearns dkearns force-pushed the runtime-vim-syntax-contained-commands branch from 29d0fa6 to 9cadc0a Compare March 11, 2026 16:08
@dkearns

dkearns commented Mar 16, 2026

Copy link
Copy Markdown
Contributor Author

Sorry @mao-yining, I missed your query.

Yes, it should fix that issue but that part is still on my machine. I'll update this PR soon.

@dkearns dkearns force-pushed the runtime-vim-syntax-contained-commands branch 4 times, most recently from 80cad4a to 26b6f68 Compare March 23, 2026 01:24
@dkearns dkearns force-pushed the runtime-vim-syntax-contained-commands branch 2 times, most recently from a6b2138 to 4e08d9a Compare April 26, 2026 10:26
@dkearns dkearns force-pushed the runtime-vim-syntax-contained-commands branch 2 times, most recently from 8833a2c to d6714e2 Compare May 13, 2026 15:41
Comment thread runtime/syntax/generator/vim.vim.base Outdated
@dkearns dkearns force-pushed the runtime-vim-syntax-contained-commands branch 3 times, most recently from f059011 to 05dd6de Compare May 18, 2026 09:42
Comment thread runtime/syntax/generator/vim.vim.base Outdated
" User Command Highlighting: {{{2
" syn match vimUsrCmd '^\s*\zs\u\%(\w*\)\@>\%([<.(#[]\|\s\+\%([-+*/%]\=\|\.\.\)=\)\@!'
" syn match vimUsrCmd contained '\u\%(\w*\)\@>\%([<.(#[]\|\s\+\%([-+*/%]\=\|\.\.\)=\)\@!' nextgroup=vimBang
syn match vimUsrCmd contained '\%#=1\<\u\w\+\>\%([![:space:]]\|$\)\@=' nextgroup=vimBang

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • \u\w\+ will match invalid patterns like :My_Invalid_Command. It needs to be [:alnum:].
  • It would be easier to read with very magic to reduce the \ overload.
  • POSIX character classes throughout would be better too.
  • Characters (like vertical tab and line-end) in [:space:], if used after a command, give errors. A tab or space only is allowed, so [:blank:] should replace [:space:]:
syn match vimUsrCmd	contained	'\v<[[:upper:]][[:alnum:]]+>%([[:blank:]!]|$)@=' nextgroup=vimBang

Illustrating with /\v<[[:upper:]][[:alnum:]]+>%([[:space:]!]|$)@= why it should be [:blank:]:
Image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • \u\w\+ will match invalid patterns like :My_Invalid_Command. It needs to be [:alnum:].

Fixed.

  • It would be easier to read with very magic to reduce the \ overload.

I don't want to mix pattern styles. The default is used by about 95% of the syntax files and also gets some useful highlighting.

"Easier to read" also depends on what you've been reading and for how long. :)

  • POSIX character classes throughout would be better too.

For aesthetics? The \u atoms are faster.

  • Characters (like vertical tab and line-end) in [:space:], if used after a command, give errors. A tab or space only is allowed, so [:blank:] should replace [:space:]:

They're interchangeable in this syntax file, if you allow for the invalid syntax, and in this case it catches the pathological ^@ case. I'll update the use of [:space:] to [:blank:] throughout the file in a different commit in the interests of correctness.

I expect the pattern can be simplified further to something more like \u[[:alnum:]]*\%([^[:alnum:]]\|$\)\@=. It's impossible to match perfectly without the actual user command list, we can only hope for tasteful use of whitespace.

syn match vimUsrCmd	contained	'\v<[[:upper:]][[:alnum:]]+>%([[:blank:]!]|$)@=' nextgroup=vimBang

Illustrating with /\v<[[:upper:]][[:alnum:]]+>%([[:space:]!]|$)@= why it should be [:blank:]: Image

They're all valid matches for a user command as far as I'm concerned. We don't try to invalidate earlier matches or entire commands based on later syntax errors.

The last match should be valid and is executed as

MyHelp
vim9cmd

@dkearns dkearns force-pushed the runtime-vim-syntax-contained-commands branch 8 times, most recently from d960e6c to 2b889f9 Compare May 29, 2026 17:28
@dkearns dkearns force-pushed the runtime-vim-syntax-contained-commands branch 4 times, most recently from 0fe3893 to 58fa350 Compare June 8, 2026 19:00
- Contain Ex commands to valid syntactic contexts.
- Add full address (:range) matching.
- Match :Next, :Print, :X, :&, :~, :>, :<, :# and := commands.
- Full matching of :global and :append (with folding) commands.

For improved performance, use :syn-keyword to match all commands except
when immediately following \w range characters where :syn-match is used.

Fixes:
- vim#20250 (variables with s_ prefix are wrongly highlighted)
- vim#17543 (do not highlight vim commands within :runtime)
- vim#16937 (do not highlight vim commands after packadd)
- vim#14895 (incorrect highlighting of Vim syntax)
- vim#14020 (insert commands)

Signed-off-by: Doug Kearns <dougkearns@gmail.com>
@dkearns dkearns force-pushed the runtime-vim-syntax-contained-commands branch from 58fa350 to b9eb3a5 Compare June 13, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants