Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViM syntax highlighting based on column

I have a column-formatted text file that I'd like highlighted in ViM. I want to highlight the file like this:

  • Column 1-60: no highlighting
  • Column 61-65: red
  • Column 66-70: blue
  • Column 71-80: green

I have seen examples of highlighting based on regular expressions or keywords, but I'm not sure how to do this based solely on the column of the file.

Is this even possible?

like image 578
jlconlin Avatar asked Mar 26 '14 15:03

jlconlin


1 Answers

It's actually really easy to do because vim has a pattern syntax that matches particular column numbers:

syn region Red start="\%61c" end="\%66c"
syn region Blue start="\%66c" end="\%71c"
syn region Green start="\%71c" end="\%81c"

hi Red ctermfg=Red guifg=Red
hi Blue ctermfg=Blue guifg=Blue
hi Green ctermfg=Green guifg=Green
like image 139
Geoff Reedy Avatar answered Sep 22 '22 09:09

Geoff Reedy