0

I have been trying to get through the syntax file documentation on vim help,
https://vimhelp.org/syntax.txt.html#%3Asyn-files
but it's quite the read and I figured someone here may know how to go about what I'm trying to do.


I do most of my note taking in vim. I have made a simple syntax file for better organizing my thoughts but I'm looking to expand it as I only get two colors at the moment. This is my current file:

if exists("b:current_syntax")     
  finish                          
endif                             
                                  
syn match keywordObject "=="      
syn match keywordObject "\["      
syn match keywordObject "\]"      
syn match keywordObject "]=="     
syn match keywordIfFalse "=="     
syn match keywordIfTrue "::"      
syn match keyworActor "--"     

syn match keywordAs "*"    
syn match comment "#.*$"          
                                  
let b:current_syntax = "notes"    
                                  
hi def link keywordObject Keyword 
hi def link keywordIfFalse Keyword
hi def link keywordIfTrue Keyword 
hi def link keywordActor Keyword  
hi def link keywordAs Keyword     
hi def link comment Keyword       

This lets me organize my thoughts better as I use Lines of ==, --, or :: to divide my notes into sections. Bullet points *, are also colored.

I would like to squeeze some additional functionality out of this, and also get more color as everything but the comments are the same yellow color.

Ideally:

!! Text surrounded by exclamation marks colored bright red to mark importance !!
?? Text surrounded by question marks colored bright pink to mark questions ??

//
Text encased by slashes as light green to mark a misc
idea that's interesting and loosely relevant, but can
be ignored if reading notes for review
\\

* Bullet points (just the bullet not the following text) as
  light yellow to further be distinguished

But I am not too picky about what the colors are if there is a limitation, I would just like a bit more variety. Thanks to any help. I would like this to be achieved through just a .vim syntax file and without any plugins.

3
  • You might want regions for the first two
    – D. Ben Knoble
    Sep 21, 2021 at 21:22
  • Could I have an example of a functional region?
    – jf4i2d
    Sep 21, 2021 at 22:44
  • I've done something similar for help files I've written. Can't give you the _vimrc mapping but the following syntax highlights text wrapped in ! syntax match myIgnoreHs /!/ contained conceal syn match myhelpvSpecial "!.*!" contains=myIgnoreHs hi def link myhelpvSpecial mySpecial The followig assigns the colour SynColor myspecial term=bold cterm=NONE ctermfg=Black gui=NONE guifg=#000000 guibg=LightYellow
    – Steve
    Sep 22, 2021 at 0:30

1 Answer 1

1

Here are some examples. (Note that your keywordAs already covers the bullet, you just need to highlight it as you want.)

When the delimiters are always on the same line, this is probably the simplest way to go:

syntax match Important /!!.*!!/

But to be more flexible, allowing delimiters anywhere, use a region:

" Don't use Question; it's a `:help highlight-default`
syntax region MyQuestion start='??' end='??'
syntax region Misc start='//' end='\\\\'

Then add some highlights. You can link to groups that already have colors you like (see :help highlight-default and :help group-name), or just make your own:


highlight def link Important Error
highlight def MyQuestion ctermfg=magenta
highlight def Misc ctermfg=green

Note that these don't overlap by default. If you need to nest them, have a look at contains.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.