This question is related to this one.
Damian Conway provided a nice snippet for marking excessive line length in his recent OSCON 2013 talk about Vim.
highlight ColorColumn ctermbg=magenta
call matchadd('ColorColumn', '\%81v', 100)
which results in this:
It works great when using console Vim. However, changing the ctermbg=magenta
part to guibg=Magenta
only highlights the character, but doesn't color it in magenta.
How can I make this work for gVim correctly?
Best Answer
Umm, works for me? As a reference, I'm running Vim v7.4 patch 335. (it's not bleeding much!!)
I added the following two lines to my
.vimrc
:Reloaded vim and taa-daa! The characters at the 81st position were magically magenta-ized.
EDIT: As per the comments below, we discovered that @isxek needed to put these two lines LAST in their .vimrc file. Evidently, the colorscheme used (Molokai) sets the ColorColumn highlight scheme. I didn't see this issue since I set the ColorColumn highlight AFTER everything's loaded, essentially performing the same thing as 'putting the lines last'.
Personally, I'd recommend using a unique
Group
identifier so you don't mess with the highlight colors set for the actualColorColumn
highlighting group.Works for both vim and gvim.
Have you tried/Do you use
ColorColumn
? Relatively new option in Vim to highlight a column (or columns!) based ontextwidth
. Was added withversion 7.3
. Very handy!I use it thusly:
So I essentially have two lines on my display, shown at
textwidth + 2
and at position120
, as my default. I've grabbed a screenshot and moved the lines withset colorcolumn=+2,90
so it isn't too wide for here. Looks like this:You can see the two vertical grey lines, positioned at
textwidth + 2
, and at position90
. Here, mytextwidth
was set to 78, so the lines are positioned at 80, and 90 characters out.Now, you COULD use the two lines you've got to add a form of
colorcolumn
for a pre-v7.3 version of vim. Stick them in anelse
clause of the version check block above.