1

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?

dylnmc
  • 3,810
  • 4
  • 26
  • 42

1 Answers1

3

-- 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
romainl
  • 186,200
  • 21
  • 280
  • 313
  • Well, thanks. That is pretty crazy vimming for me. Also, it doesn't seem to work for me. I don't need it as I am just curious about it, but I am pretty sure it doesn't work in my vim. I have `set t_Co=256` with *solarized* in linux, but I don't think any of that would matter, right? – dylnmc Jun 08 '15 at 05:34
  • Well, I tried it before submitting my answer and it worked but… not anymore. Weird. – romainl Jun 08 '15 at 07:17
  • If it helps I tried making things lower case and upper case (for RulerFormat vs rulerformat) and nothing seemed to do the trick. Also, I found a better way of doing what I want (using `:set laststatus=2` `:set statusline="blablabla"`. It would still be cool to figure out this vimscript stuff. – dylnmc Jun 08 '15 at 08:16
  • 1
    Using `statusline` is probably the way to go. It replaces `ruler` completely. Highlighting `statusline` is rather weird because of the way redraws work in Vim. Plugin such as [powerline](https://github.com/powerline/powerline) or [airline](https://github.com/bling/vim-airline) can take care of these kind of details, but if you insist on doing it on your own, there are a few success stories around. :) – Sato Katsura Jun 09 '15 at 05:03
  • @SatoKatsura :) cheers; I don't really have time, but it would be a fun small project in the future.jkkkk <- vim... I tried to go up and right. haha. I do that too much. (I just hit escape, too.) – dylnmc Jun 09 '15 at 06:26
  • @romainl I accepted, but it still doesn't quite work. If you have time, could you perhaps update it, if you know how or perhaps add a comment saying that it doesn't quite work. Thanks; I've been looking up vim for a while, and you pop up a lot. Keep up the good work. Thanks – dylnmc Jun 09 '15 at 06:27
  • Is it your question that is not clear or me who didn't understand it? Do you want to highlight the value of the `'rulerformat'` option in your `vimrc` or do you want your *ruler* to be highlighted? My answer is an attempt to address the former. – romainl Jun 09 '15 at 07:15
  • I did read rulerformat help. It doesn't explain User1 from what I recall. You did address my original and apparently confusing inquiry.:q – dylnmc Jun 09 '15 at 07:59
  • In `:h 'ruler'` you have a pointer to `:h 'rulerformat'` where you have a pointer to `:h 'statusline'` which tells you how to use highlighting and points you toward `:h User1` for further info on "user" highlight groups 1 to 9. Also I second Sato's comment on `'statusline'`. – romainl Jun 09 '15 at 08:12