2017-08-14 94 views

回答

2

.vimrc有這個代碼:

function! HiInterestingWord(n) " {{{2 
    " Save our location. 
    normal! mz 
    " Yank the current word into the z register. 
    normal! "zyiw 
    " Calculate an arbitrary match ID. Hopefully nothing else is using it. 
    let mid = 77750 + a:n 
    " Clear existing matches, but don't worry if they don't exist. 
    "silent! call matchdelete(mid) 
    try 
     call matchdelete(mid) 
    catch 'E803' 
     " 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) 
    endtry 
    " Move back to our original location. 
    normal! `z 
endfunction 

"clear all highlighting 
function! ClearAllHi() 
    for i in range(1,6) 
     let mid = 77750 + i 
     silent! call matchdelete(mid) 
    endfor 
endfunction 

nnoremap <silent> <leader>0 :call ClearAllHi()<cr> 
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> 

hi def InterestingWord1 guifg=#000000 ctermfg=16 guibg=#ffa724 ctermbg=214 
hi def InterestingWord2 guifg=#000000 ctermfg=16 guibg=#aeee00 ctermbg=154 
hi def InterestingWord3 guifg=#000000 ctermfg=16 guibg=#8cffba ctermbg=121 
hi def InterestingWord4 guifg=#000000 ctermfg=16 guibg=#b88853 ctermbg=137 
hi def InterestingWord5 guifg=#000000 ctermfg=16 guibg=#ff9eb8 ctermbg=211 
hi def InterestingWord6 guifg=#000000 ctermfg=16 guibg=#ff2c4b ctermbg=195 
"}}} 

這可以讓你按<leader> + 1-6下光標在不同顏色的高發光字;按兩下清除突出顯示。 (您可以更改hi def...中的顏色)命令。並且<leader>+0清除所有亮點。

你可以把代碼放在你的vimrc中試試。

它的工作原理是這樣的:

enter image description here

+0

我不認爲這就是OP所要求的:除了Search之外,他基本上需要一個單獨的'SearchCurrent'高亮組。 –

1

人都用過solution基於達米安康威的談話

" Damian Conway's Die Blinkënmatchen: highlight matches                       
nnoremap <silent> n n:call HLNext(0.1)<cr> 
nnoremap <silent> N N:call HLNext(0.1)<cr> 

function! HLNext (blinktime) 
    let target_pat = '\c\%#'[email protected]/ 
    let ring = matchadd('ErrorMsg', target_pat, 101) 
    redraw 
    exec 'sleep ' . float2nr(a:blinktime * 1000) . 'm' 
    call matchdelete(ring) 
    redraw 
endfunction 

但就個人而言,我更喜歡簡單的,雖然這個亮點全line

"cursorline and it's highlighting                            
set cursorline 
hi CursorLine cterm=NONE ctermbg=NONE ctermfg=green 
相關問題