Novice C
Novice C

Reputation: 1374

Secondary text color for first 50 char of line 1 in vim

I am trying to cherry-pick a few features I found interesting in a screenshot of fugitive-vim, since I can't fully appreciate why I would want to run git commands while currently writing a gitcommit file.

One feature I'd like to add is changing the text color (or highlight the background) of the first 50 characters only in the first row (the subject line). I'm just started learning to edit .vimrc today, but can't figure it out.

Upvotes: 0

Views: 266

Answers (1)

DJMcMayhem
DJMcMayhem

Reputation: 7669

You can do this:

highlight SOF guifg=RED
syn match SOF '\%1l^.\{,50}'

What this does is defines a syntax group named SOF (Start of File), and sets the gui foreground for anything in that group to be red. To see what other options for highlighting you have, see

:help highlight

and

:help gui-colors

Then, the second line defines what regex match should be included in the syntax group. In this case, the regex is

'\%1l^.\{,50}'

Which translates to "Up to any 50 characters on the first line."

If you don't feel like going to that much trouble, you could also install the tpope/vim-git plugin. I haven't used or tried it, but it has a filetype plugin for git commits, so it should achieve some basic git-style syntax highlighting without too much effort.

Upvotes: 1

Related Questions