2017-08-14 11 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を押すことができます。強調表示を消去するために2回押します。 (hi def...の色を変えることができます)コマンド。 <leader>+0すべてのハイライトをクリアします。

コードをvimrcに入れて試してみてください。

それは次のように動作します。

enter image description here

+0

私はそれがOPが求めているとは思わない:彼は基本的に 'Search'に加えて別々の' SearchCurrent'ハイライトグループを望んでいる。 –

1

人々はダミアン・コンウェイの話

" 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 

しかし、個人的に基づいてsolutionを使用している、私は、このハイライト全体ものの、シンプルなものを好みますライン

"cursorline and it's highlighting                            
set cursorline 
hi CursorLine cterm=NONE ctermbg=NONE ctermfg=green 
関連する問題