-
Notifications
You must be signed in to change notification settings - Fork 0
/
words.vim
56 lines (49 loc) · 1.76 KB
/
words.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
" Highlight matching words, highlight word under the cursor
"
" Author: Bimba Laszlo <https://github.com/bimlas>
" Source: https://github.com/bimlas/vim-high
" License: MIT license
"
" Inspired by:
" https://github.com/lfv89/vim-interestingwords
"
" An example setup to get nicer colors:
"
" let g:high_lighters = {'words': {'_hlgroups': []}}
" for color in ['8ccbea', 'a4e57e', 'ffdb72', 'ff7272', 'ffb3ff', '9999ff']
" exe 'autocmd ColorScheme,VimEnter *
" \ highlight! HighWords'.color.' guibg=#'.color.' guifg=#000000'
" let g:high_lighters.words._hlgroups += ['HighWords'.color]
" endfor
function! high#light#words#Define()
return {
\ '_hlgroups': ['Pmenu', 'PmenuSel', 'PmenuSbar'],
\ '_map_add': '<Leader>k',
\ '_map_clear': '<Leader>K',
\ '__auto_highlight': 0,
\ '__init_function': function('s:Init'),
\ }
endfunction
function! s:Init(options) "{{{
exe 'nnoremap <silent> '.a:options._map_add.' :call high#light#words#AddWord(expand("<cword>"))<CR>'
exe 'nnoremap <silent> '.a:options._map_clear.' :call high#light#words#ClearWords()<CR>'
let s:hlgroups_index = 0
endfunction "}}}
function! high#light#words#AddWord(cword) "{{{
" TODO: return if group not enabled
let words = high#group#GetSettings('words')
let clone = high#utils#Clone(words)
call high#group#AddMember(clone)
let clone.pattern = '\<'.a:cword.'\>'
" Set up the highlight group and switch to the next one.
let clone.hlgroup = words._hlgroups[s:hlgroups_index]
let s:hlgroups_index += 1
if s:hlgroups_index >= len(words._hlgroups)
let s:hlgroups_index = 0
endif
call high#match#Highlight(clone, 1)
endfunction "}}}
function! high#light#words#ClearWords() "{{{
let words = high#group#GetSettings('words')
call high#LightGroup(words, 0)
endfunction "}}}