hash syntax highlighting

66 views
Skip to first unread message

Ritchie Lee

unread,
Jun 14, 2016, 3:19:54 PM6/14/16
to vim_use
Hello,

I'm looking for hash syntax highlighting capability --- words that are not highlighted as keywords, such as user variables, etc., are hashed to a random color. The color would be consistent for the same variable though. This makes it easy to spot where the variable is being used at a glance.

If this sort of plugin is not already available, how would I go about implementing it? Or adding it to an existing syntax plugin?

Thanks!

Victor Roemer

unread,
Jun 15, 2016, 3:03:33 AM6/15/16
to vim...@googlegroups.com
HI Ritchie,

Maybe this is something you'll find useful.

I use an older plugin highlights.vim [1] and have added the following to my .vimrc

--- snip ---
" The leader defaults to backslash, so (by default) this maps \* and \g* (see :help Leader).
" These work like * and g*, but do not move the cursor and always set hls.
map         <Leader>*       :let @/ = '\<'.expand('<cword>').'\>'\|set hlsearch<C-M>
map         <Leader>g*      :let @/ = expand('<cword>')\|set hlsearch<C-M>
nm          <Leader>1       :Highlight 1 <C-R>='\<'.expand("<cword>").'\>'<CR><CR>
nm          <Leader>2       :Highlight 2 <C-R>='\<'.expand("<cword>").'\>'<CR><CR>
nm          <Leader>3       :Highlight 3 <C-R>='\<'.expand("<cword>").'\>'<CR><CR>
nm          <Leader>4       :Highlight 4 <C-R>='\<'.expand("<cword>").'\>'<CR><CR>
nm          <Leader>5       :Highlight 5 <C-R>='\<'.expand("<cword>").'\>'<CR><CR>
nm          <Leader>0       :Hclear <C-R>='\<'.expand("<cword>").'\>'<CR><CR>
nm          <Leader>*0      :Hclear *<CR><CR>
--- end snip ---


And this gives me a quick and efficient way to uniquely highlight the keyword under the cursor with one of <Leader>1-9. Turn off highlighting the specific keyword under cursor with <Leader>0; to disable all highlights I execute ":hclear".

You'll additionally need to provide your own hightlights.csv in the same directory as highlights.vim. Here is mine as an example

--- snip ---
hlnum,ctermfg,ctermbg,guifg,guibg
1,white,red,white,red
2,white,blue,white,blue
3,white,green,white,green
4,white,magenta,white,magenta
5,white,black,white,black
6,white,red,white,red
7,white,blue,white,blue
8,white,green,white,green
9,white,magenta,white,magenta
--- end snip ---




--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages