I'm trying to do a syntax highlight regex in my _vimrc etc to highlight specific commands in comments for a visual cue.
The match should be \s
followed by either a #
or !
then a \s
or a \S
then anything until the next \s
followed by either a #
or a !
then a \s
eg the following lines should match with the bolded parts being what I want highlighted.
================================
" To run this use # <leader>R !
to execute the command
#highlight #
various items
" another way is to # highlight #
the line
=================================
So far I've tried
syn match myhelpComment "\s#\|!\(\s\|\S\)\+[#!]\s"
The regex above matches the \s#
but not \s!
below but doesn't match the text in between them.
syn match myhelpComment "\s#\|!\(\s\|\S\).*\s[#!]\s"
The regex above matches the bolded areas below which isn't quite right
" To run this use
# R ! ` to execute the command
" another way is to # highlight #
the line
This works in help.vim not in vim.vim and I have absolutely no idea why
syn match myhelpComment "\s[:#!].\{-}\s[:#!]\s" --- Works in help.vim
But the following in vim.vim and
syn match myvimSpecial "\s[:#!].\{-}\s[:#!]\s"
hi def link myvimSpecial mySpecial
syncolor.vim
SynColor mySpecial term=bold cterm=NONE ctermfg=LightRed ctermbg=LightBlue gui=NONE guifg=LightRed guibg=#E6E600
Any suggestions on how to get the regex I want to work or why the one that works in help.vim works but doesn't work in vim.vim?
The reason that works in help, but not Vim files is that your definition interferes with the default syntax/vim.vim
definitions. As you'd like to match inside comments, your :syn match
has to be containedin=...
the corresponding group for comments:
syn match myvimSpecial "\s[:#!].\{-}\s[:#!]\s" containedin=vimLineComment