Skip to content

Commit e25e6f2

Browse files
author
Luis Vasconcellos
committed
First commit
0 parents  commit e25e6f2

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

plugin/interestingwords.vim

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
" --------------------------------------------------------------------
2+
" This plugin was inspired and based on Steve Losh's interesting words
3+
" .vimrc config https://www.youtube.com/watch?v=xZuy4gBghho
4+
" --------------------------------------------------------------------
5+
6+
let s:interestingWords = []
7+
let s:mids = []
8+
9+
function! ColorWord(n)
10+
let currentWord = expand('<cword>') . ''
11+
12+
if (index(s:interestingWords, currentWord) == -1)
13+
let mid = 86750 + a:n
14+
15+
call add(s:interestingWords, currentWord)
16+
call add(s:mids, mid)
17+
18+
normal! mz
19+
normal! "zyiw
20+
21+
let pat = '\V\<' . escape(@z, '\') . '\>'
22+
23+
call matchadd("InterestingWord" . a:n, pat, 1, mid)
24+
25+
normal! `z
26+
else
27+
call UncolorWord()
28+
endif
29+
endfunction
30+
31+
function! UncolorWord()
32+
let currentWord = expand('<cword>') . ''
33+
let currentWordPosition = index(s:interestingWords, currentWord)
34+
35+
if (currentWordPosition > -1)
36+
let mid = s:mids[currentWordPosition]
37+
38+
silent! call matchdelete(mid)
39+
40+
call remove(s:interestingWords, currentWordPosition)
41+
call remove(s:mids, currentWordPosition)
42+
endif
43+
endfunction
44+
45+
function! WordNavigation(direction)
46+
let currentWord = expand('<cword>') . ''
47+
48+
if (index(s:interestingWords, currentWord) > -1)
49+
if (a:direction == 'forward')
50+
normal! *
51+
endif
52+
53+
if (a:direction == 'backward')
54+
normal! #
55+
endif
56+
else
57+
if (a:direction == 'forward')
58+
silent! normal! n
59+
endif
60+
61+
if (a:direction == 'backward')
62+
silent! normal! N
63+
endif
64+
endif
65+
endfunction
66+
67+
function! InterestingWords()
68+
call ColorWord(len(s:interestingWords) + 1)
69+
endfunction
70+
71+
function! UncolorAllWords()
72+
if (len(s:mids) > 0)
73+
for mid in s:mids
74+
call matchdelete(mid)
75+
endfor
76+
77+
call remove(s:mids, 0, -1)
78+
call remove(s:interestingWords, 0, -1)
79+
endif
80+
endfunction
81+
82+
hi def InterestingWord1 guifg=#000000 ctermfg=16 guibg=#ffa724 ctermbg=214
83+
hi def InterestingWord2 guifg=#000000 ctermfg=16 guibg=#aeee00 ctermbg=154
84+
hi def InterestingWord3 guifg=#000000 ctermfg=16 guibg=#ff0000 ctermbg=121
85+
hi def InterestingWord4 guifg=#000000 ctermfg=16 guibg=#b88823 ctermbg=137
86+
hi def InterestingWord5 guifg=#000000 ctermfg=16 guibg=#0000ff ctermbg=211
87+
hi def InterestingWord6 guifg=#000000 ctermfg=16 guibg=#ff2c4b ctermbg=222
88+
89+
nnoremap <silent> K :call InterestingWords()<cr>
90+
nnoremap <silent> <leader>c :call UncolorAllWords()<cr>
91+
92+
nnoremap <silent> n :call WordNavigation('forward')<cr>
93+
nnoremap <silent> N :call WordNavigation('backward')<cr>

0 commit comments

Comments
 (0)