Skip to content

Instantly share code, notes, and snippets.

@bruceLee-kungFu
Created May 12, 2016 20:48
Show Gist options
  • Save bruceLee-kungFu/13d32c1ff5690af009286ccb4451df61 to your computer and use it in GitHub Desktop.
Save bruceLee-kungFu/13d32c1ff5690af009286ccb4451df61 to your computer and use it in GitHub Desktop.
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