How to highlight rulerformat

1.5k views Asked by At

I want highlight the rulerformat in my .vimrc.

I have

set ruler
set rulerformat=%55(%{strftime('%a\ %b\ %e\ %I:%M\ %p')}\ %5l,%-6(%c%V%)\ %P%)

I have subsequently tried all of the following:

hi rulerformat ctermbg=1
hi rulerformat ctermbg=red
hi Group1 ctermbg=red "if you modify the rulerformat slightly you can try to access group 1

I don't necessarily want it to be red, but I thought that would stand out the most; anyway, I just cannot get it to work, and I didn't really find anything online (a somewhat unintensive search yielded nothing much). So, how does one highlight the rulerformat?

1

There are 1 answers

9
romainl On BEST ANSWER

-- edit --

I think I completely missed the point of your question.

What you seem to want is not a way to highlight the value of 'rulerformat' in your vimrc (as your repeated emphasis on rulerformat, your title and your introductory sentence imply) but your actual ruler, at the bottom of the window.

This is easy to achieve if you follow the instructions at :help 'statusline':

hi User1 ctermfg=1 guifg=#80000
set ruler
:set rulerformat=%55(%1*%{strftime('%a\ %b\ %e\ %I:%M\ %p')}\ %5l,%-6(%c%V%)\ %P%)%*

But you would already have a solution if you cared to read:

:help 'ruler'
:help 'rulerformat'
:help 'statusline'
:help hl-User1

-- endedit --

The value of 'rulerformat' is highlighted by default but not as a whole: each character is highlighted individually according to the rules defined in $VIMRUNTIME/syntax/vim.vim.

If you want to highlight the whole value with a single color, you will need to add your own rule to your vimrc:

hi RulerFormat ctermbg=1
augroup RulerFormat
    autocmd!
    autocmd WinEnter,BufEnter vimrc call matchadd('RulerFormat', 'rulerformat=\zs.\+', -1)
augroup END