Difference between revisions of "Vim syntax patch"

From WTFwiki
Jump to navigation Jump to search
(Created page with "<code> if matchstr(bufname("%"), "25-fw-names") != "" syn region A start=/- [adr]=[0-9]/ end=/^/ contains=C,E,D syn match C /[a-z]\+\ze=/ contained syn match D /=\zs[^=]...")
 
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
<code>
+
How to make a syntax patch for [[vim]], by which I mean you can build some sugar on top of an already syntax-highlighted file format.  I patched this onto YAML, and the trick is to stick it in '''~/.vim/after/syntax/yaml.vim''' so it gets loaded last.
if matchstr(bufname("%"), "25-fw-names") != ""
 
  syn region A start=/- [adr]=[0-9]/ end=/^/ contains=C,E,D
 
  syn match C /[a-z]\+\ze=/ contained
 
  syn match D /=\zs[^=]\+\ze / contained
 
  syn match E /=\zs[^=]\+\ze$/ contained
 
  
  hi def link C Type
+
It looks like this: https://imgur.com/g3xX6lr
  hi def link D Keyword
+
 
  hi def link E Constant
+
if matchstr(bufname("%"), "25-fw-names") != ""
endif
+
  syn region A start=/- [adr]=[0-9]/ end=/^/ contains=C,E,D
</code>
+
  syn match C /[a-z]\+\ze=/ contained
 +
  syn match D /=\zs[^=]\+\ze / contained
 +
  syn match E /=\zs[^=]\+\ze$/ contained
 +
 +
  hi def link C Type
 +
  hi def link D Keyword
 +
  hi def link E Constant
 +
endif

Latest revision as of 09:37, 3 October 2023

How to make a syntax patch for vim, by which I mean you can build some sugar on top of an already syntax-highlighted file format. I patched this onto YAML, and the trick is to stick it in ~/.vim/after/syntax/yaml.vim so it gets loaded last.

It looks like this: https://imgur.com/g3xX6lr

if matchstr(bufname("%"), "25-fw-names") != ""
  syn region A start=/- [adr]=[0-9]/ end=/^/ contains=C,E,D
  syn match C /[a-z]\+\ze=/ contained
  syn match D /=\zs[^=]\+\ze / contained
  syn match E /=\zs[^=]\+\ze$/ contained

  hi def link C Type
  hi def link D Keyword
  hi def link E Constant
endif