Is it possible to change the back-gound color of the gutter for the function that I am working on? I keep loosing my place, but it would be awesome to highlight a section like below.

enter image description here

  • Approaching this differently, you could use folding. Then zx will fold everything that's not under the cursor.
    – Antony
    Dec 28 '16 at 19:19

One could (ab)use :help sign:

" define an highlight group
highlight CurrentBlock ctermbg=red ctermfg=red cterm=NONE

" define a sign
sign define currentblock text=>> texthl=CurrentBlock

" place the signs
for range(30, 40)
    execute "sign place " . i . " line=" . i . " name=currentblock file=" . expand("%:p")

" remove the signs
for range(30, 40)
    execute "sign unplace" . i

and wrap all that in a CursorMoved autocommand.

The hardest part being to actually determine where the current block starts and ends.


  • Sharing the thought - it is abuse :-)
    – ryuichiro
    Nov 30 '16 at 10:55
  • Is it possible to highlight gutter between two marks, lets say when the user places mark a and mark b, the system highlights everything in between? Nov 30 '16 at 12:33
  • Yes, you can use line("'a") to get the line number of 'a.
    – romainl
    Nov 30 '16 at 12:57

You can use my DynamicSigns plugin like this:

First, define after what rules to higlight the gutter.

fu! CustomSignExpression(lnum)
    if a:lnum < line('w0') || a:lnum > line ('w$')
        return 0
    if !exists("#CustomSignExpression#CursorMoved")
        augroup CustomSignExpression
            au VimResized,CursorMoved * :unlet! s:min s:max | :UpdateSigns
        augroup end
    if !exists("s:min")
        let s:min=search('^{', 'bn')
        let s:max=search('^}', 'n')
    if a:lnum < s:min || a:lnum > s:max
        return 0
        return 'Gutter2'

This function is a slight adjustment, to what is documented in the help at :h :SignExpression. You most likely want to adjust the search patterns, e.g. according to your screenshot you probably want something like ^\w\+(.*)\s*{ as the search pattern for the start of a function.

Now you can use :SignExpression CustomSignExpression(v:lnum) and it should highlight your gutter column with red. If you want a different highlighting, Adjust the 'Gutter' line inside the function. See the help at :h Signs-Highlight for what is predefined and how you can change that.


I don't know of a way to highlight the gutter (and the fact that the only highlight groups for that region are LineNr and CursorLineNr makes me think that's not possible), but you could use :match the given function:

:highlight WorkInProgress ctermbg=DarkGray
:match WorkInProgress /^TEST_F(CborEncoder, write32bit_uint) {\_.\{-}\n}/

When you're done, you can use :match none to clear it.


I was really surprised by the existence of SignColumn, so I decided to use it in this strange way. The whole function is not highlighted

"if a change in a text, call SetSign() function
au TextChanged,TextChangedI * :cal SetSign()

function! SetSign()
   "remove signs 
   sign unplace *
   "define a sign
   sign define lastMod text=* texthl=Search
   "place a sign
   exe ":sign place 1 line=" . line("'.") . " name=lastMod file=" . expand("%:p")

"remove the signs manually
nnoremap <leader>u :sign unplace *<CR>

but at least the last changed line in code is highlighted at the side. If you want to remove the sign, just press <leader>+u in normal mode.

Nevertheless, this solution is not so great, so it is probably better to use `., g; and g,, or gi to get to the position where the last change was made (and which I presumed was the position of the function you working on).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.