brianmearns
brianmearns

Reputation: 9967

Syntax highlight empty virtual columns

Is it possible to include empty virtual columns in a syn match group? I want to highlight a block of text as though it's in a terminal window by giving it a black background, but I want the "terminal" to always be 80-columns wide, even if the text in that line is shorter.

I tried sync match cmdLineOutput '.*\%<81v' but that only matches if there are actual characters there. I guess I need something to replace . which matches characters and empty columns.

Upvotes: 2

Views: 203

Answers (3)

Ingo Karkat
Ingo Karkat

Reputation: 172540

As a text editor, there's no need for highlighting beyond the text, so you need to hack it. The already mentioned 'colorcolumn' works for specific columns, but in all lines in the window; if you need highlighting of specific lines, you can use signs. Unfortunately, those highlight all columns in the specific lines (and show the sign column in addition).

:sign define demo linehl=Search
:exe "sign place 2 line=3 name=demo file=" . expand('%:p')

If you really need both specific lines and columns, I think you have to add trailing whitespace to those lines, and then you're able to use the normal :syn match on it.

Upvotes: 2

mkrieger1
mkrieger1

Reputation: 23144

The colorcolumn option approximately does what you want. Normally, it highlights only a single column, but you can also specify a list of columns. In your case you could emulate what you want by

:set colorcolumn=81,82,83,84,85,... (how many you want)
:hi ColorColumn ctermbg=black

Upvotes: 1

Mariano Macchi
Mariano Macchi

Reputation: 242

You could try playing with colorcolumn:

highlight ColorColumn ctermbg=black
let &colorcolumn=join(range(1,80), ',')

This makes a black background for the first 80 columns, but it makes screen redrawing slower.

See :h colorcolumn for more options.

Upvotes: 2

Related Questions