Is it possible to mark a range of text in Vim and change the highlight color of it (to red) than select another range of text and change that color (to green) keeping the previous highlight and so on?
The basic stuff to start from is:
:hi Green guibg=#33ff33
:syntax region Green start=/\%20l/ end=/\%30l/
What it does:
Now you can write a function or/and command which takes visually selected text and applies one of the multiple predefined color groups to it. Once you have that function -- bind it to your keys: for example \g for green, \r for red,
Upd:
And here is a bit of vimscript:
function! HighlightRegion(color)
hi Green guibg=#77ff77
hi Red guibg=#ff7777
let l_start = line("'<")
let l_end = line("'>") + 1
execute 'syntax region '.a:color.' start=/\%'.l_start.'l/ end=/\%'.l_end.'l/'
endfunction
vnoremap <leader>g :<C-U>call HighlightRegion('Green')<CR>
vnoremap <leader>r :<C-U>call HighlightRegion('Red')<CR>
Note:
It can't reapply the highlighting (Green to Red for instance).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With