Created
May 12, 2016 20:48
-
-
Save bruceLee-kungFu/13d32c1ff5690af009286ccb4451df61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! HiInterestingWord(n) " {{{ | |
" Save our location. | |
" normal! mz | |
let view = winsaveview() | |
" Yank the current word into the z register. | |
normal! "zyiw | |
" Calculate an arbitrary match ID. Hopefully nothing else is using it. | |
let mid = 86750 + a:n | |
" Clear existing matches, but don't worry if they don't exist. | |
silent! call matchdelete(mid) | |
" Construct a literal pattern that has to match at boundaries. | |
let pat = '\V\<' . escape(@z, '\') . '\>' | |
" Actually match the words. | |
" call matchadd("InterestingWord" . a:n, pat, 1, mid) | |
tabdo call matchadd("InterestingWord" . a:n, pat, 1, mid) | |
" Move back to our original location. | |
" normal! `z | |
call winrestview(view) | |
endfunction " }}} | |
" Mappings {{{ | |
nnoremap <silent> <leader>1 :call HiInterestingWord(1)<cr> | |
nnoremap <silent> <leader>2 :call HiInterestingWord(2)<cr> | |
nnoremap <silent> <leader>3 :call HiInterestingWord(3)<cr> | |
nnoremap <silent> <leader>4 :call HiInterestingWord(4)<cr> | |
nnoremap <silent> <leader>5 :call HiInterestingWord(5)<cr> | |
nnoremap <silent> <leader>6 :call HiInterestingWord(6)<cr> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment