Vim: Highlight a Single Character at Column 80
Question:
So, in good PEP fashion I am attempting to keep column width to below 80 for Python code. I have been using the colorcolumn=80
option in my .vimrc but in the terminal (I am not a fan of gvim or macvim) the effect of a fully black stripe down column 80 is too jarring for my taste. I also have no desire to enable wrapping as there are many cases where I need to go beyond the line.
I had read somewhere that someone set it to highlight only the single character at column n in a bright color and this sounds like a perfectly subtle visual cue.
Unfortunately for the life of me and despite my Googlefu I cannot locate how this was accomplished.
Any takers?
Answers:
hi Bang ctermfg=red guifg=red
match Bang /%>79v.*%<81v/
this two lines will hi the char in 80th column, only if there is a char. The color I used is red, for example. you can pick other sexy colors (fg/bg).
You can keep using colorcolumn
, with no background color and red foreground color:
:hi ColorColumn ctermbg=NONE ctermfg=red
Before:
After:
So, in good PEP fashion I am attempting to keep column width to below 80 for Python code. I have been using the colorcolumn=80
option in my .vimrc but in the terminal (I am not a fan of gvim or macvim) the effect of a fully black stripe down column 80 is too jarring for my taste. I also have no desire to enable wrapping as there are many cases where I need to go beyond the line.
I had read somewhere that someone set it to highlight only the single character at column n in a bright color and this sounds like a perfectly subtle visual cue.
Unfortunately for the life of me and despite my Googlefu I cannot locate how this was accomplished.
Any takers?
hi Bang ctermfg=red guifg=red
match Bang /%>79v.*%<81v/
this two lines will hi the char in 80th column, only if there is a char. The color I used is red, for example. you can pick other sexy colors (fg/bg).
You can keep using colorcolumn
, with no background color and red foreground color:
:hi ColorColumn ctermbg=NONE ctermfg=red
Before:
After: