Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim adding new elements to syntax keywords using color scheme file?

I am trying to modify fortran syntax using a color scheme file.

In color scheme, these functions works fine.

hi! link fortranConditional     Function
hi! link fortranRepeat          SpecialChar
hi! link fortranBoolean         SpecialChar
hi! link fortranReadWrite       SpecialChar
hi! link fortranIO              SpecialChar
hi! link fortranConstant        Underlined 

I want to add more element into different syntax keywords too. But for now, I can only use file type auto command like this:

autocmd BufNewFile,BufRead *.f90 syn match fortranType        "[()]"
autocmd BufNewFile,BufRead *.f90 syn match fortranIntrinsic   ":"
autocmd BufNewFile,BufRead *.f90 syn match fortranConstant    "[%,]"

Is there any way that I can write autocmd BufNewFile,BufRead *.f90 only for once? Or is there other way I can add elements in color scheme files? Or the right way to do this is to create a new syntax file?

like image 869
user3716774 Avatar asked Feb 22 '26 21:02

user3716774


1 Answers

The direct answer to your question for grouping is to create a function and call that function:

autocmd BufNewFile,BufRead *.f90 call LoadFortranSyntax()

function! LoadFortranSyntax()
  syn match fortranType        "[()]"
  syn match fortranIntrinsic   ":"
  syn match fortranConstant    "[%,]"
endfunction

However the recommended and proper way of adding something to a syntax file, is using your ~/.vim/after/syntax directory. For example:

File: ~/.vim/after/syntax/fortran.vim

syn match fortranType        "[()]"
syn match fortranIntrinsic   ":"
syn match fortranConstant    "[%,]"

This is described in the help, under the topic mysyntaxfile-add.

like image 83
sidyll Avatar answered Feb 24 '26 15:02

sidyll



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!