diff options
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/vim-under-the-cursor.vim | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/plugin/vim-under-the-cursor.vim b/plugin/vim-under-the-cursor.vim new file mode 100644 index 0000000..403164a --- /dev/null +++ b/plugin/vim-under-the-cursor.vim | |||
@@ -0,0 +1,57 @@ | |||
1 | "======================================================================================================================= | ||
2 | " HIGHLIGHT_WORD_UNDER_CURSOR: | ||
3 | "======================================================================================================================= | ||
4 | |||
5 | let w:m1 = 0 | ||
6 | function! HighlightWordUnderCursor() | ||
7 | if(exists('w:m1') && w:m1 > 0) | ||
8 | silent! call matchdelete(w:m1) | ||
9 | let w:m1 = 0 | ||
10 | endif | ||
11 | let l:currentword = escape(expand('<cword>'), '.') | ||
12 | if(strlen(l:currentword) > 0) | ||
13 | let w:m1=100 | ||
14 | |||
15 | " match rgba... | ||
16 | let l:q = matchstr(expand('<cword>'), '\x\{8\}') | ||
17 | if(l:q == "") " without alpha | ||
18 | let l:q = matchstr(expand('<cword>'), '\x\{6\}') | ||
19 | let l:a = 255 | ||
20 | else " with alpha... | ||
21 | let l:a = str2nr(strpart(l:q, 6, 2), 16) | ||
22 | endif | ||
23 | |||
24 | if(l:q != "") | ||
25 | let l:r = str2nr(strpart(l:q, 0, 2), 16) * (l:a / 255.0) | ||
26 | let l:g = str2nr(strpart(l:q, 2, 2), 16) * (l:a / 255.0) | ||
27 | let l:b = str2nr(strpart(l:q, 4, 2), 16) * (l:a / 255.0) | ||
28 | let l:color = | ||
29 | \ printf('%02x', float2nr(l:r)) | ||
30 | \ . printf('%02x', float2nr(l:g)) | ||
31 | \ . printf('%02x', float2nr(l:b)) | ||
32 | \ . printf('%02x', float2nr(l:a)) | ||
33 | |||
34 | let l:brightness = (l:r / 3) + (l:g / 1) + (l:b / 8) | ||
35 | |||
36 | " echo 'q:'. l:q . ' r:' . l:r . ' g:' . l:g . ' b:' . l:b . ' a:' . l:a . ' / ' . | ||
37 | " \ (str2nr(l:a, 16) / 255.0) . ' brightness: ' . l:brightness . ' / color:' . l:color | ||
38 | |||
39 | if(l:brightness > 240) | ||
40 | exec 'highlight! ' . l:color . ' guibg=#' . strpart(l:color, 0, 6) . ' guifg=#000000' | ||
41 | else | ||
42 | exec 'highlight! ' . l:color . ' guibg=#' . strpart(l:color, 0, 6) . ' guifg=#ffffff' | ||
43 | endif | ||
44 | |||
45 | exec 'syntax clear ' . l:color | ||
46 | exec 'syntax match ' . l:color . ' /\#' . l:q . '/' | ||
47 | else | ||
48 | silent! call matchadd('Underline', '\<'.l:currentword.'\>', -1, w:m1) | ||
49 | endif | ||
50 | endif | ||
51 | endfunction | ||
52 | |||
53 | " set updatetime=100 | ||
54 | highlight! Underline cterm=underline gui=underline | ||
55 | autocmd CursorMoved,InsertLeave,TextChanged * call HighlightWordUnderCursor() | ||
56 | |||
57 | " vim: expandtab tabstop=4 sw=4 | ||