0

I have made (better said got) a syntax file for CSV files. This works fine so far.

But there is the semicolon used as seperator. I want to be able to change the seperator e.g. by a function / mapping / ...
So I have to use a variable in my pattern so I can change it from [^;]*;\? for example to [^,]*,\?.

csv.vim

syn match csvField1 /[^;]*;\?/ display           nextgroup=csvField2
syn match csvField2 /[^;]*;\?/ display contained nextgroup=csvField3
syn match csvField3 /[^;]*;\?/ display contained nextgroup=csvField4
syn match csvField4 /[^;]*;\?/ display contained nextgroup=csvField5
syn match csvField5 /[^;]*;\?/ display contained nextgroup=csvField6
syn match csvField6 /[^;]*;\?/ display contained nextgroup=csvField7
syn match csvField7 /[^;]*;\?/ display contained

hi def link csvField1 Normal
hi def link csvField2 Constant
hi def link csvField3 Special
hi def link csvField4 Identifier
hi def link csvField5 Statement
hi def link csvField6 PreProc
hi def link csvField7 Type

enter image description here

1

1 Answer 1

1

I would use the execute statement:

execute 'syn match csvField1 /[^' . g:separator . ']*' . g:separator . '\?/ display           nextgroup=csvField2'
2
  • Thanks! I made a let g:seperator = ',' then let g:pattern = '/[^' . g:seperator . ']*' . g:seperator . '\?/ and put this in every syn match line
    – Andy A.
    Commented Feb 2, 2023 at 7:19
  • Thanks for the feedback :-) Commented Feb 2, 2023 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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