Last active
August 29, 2015 14:01
-
-
Save cohalz/6d889213c95ee468b8e5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| "http://d.hatena.ne.jp/osyo-manga/20140121/1390309901 | |
| "上記のサイトのコードをカーソル下が記号列でも割と動くように改良 | |
| " 1 が設定されていれば有効になる | |
| " let g:enable_highlight_cursor_word = 0 | |
| let g:enable_highlight_cursor_word = 1 | |
| augroup highlight-cursor-word | |
| autocmd! | |
| autocmd CursorMoved * call s:hl_cword() | |
| " | |
| " カーソル移動が重くなったと感じるようであれば | |
| " CursorMoved ではなくて | |
| " CursorHold を使用する | |
| " autocmd CursorHold * call s:hl_cword() | |
| " 単語のハイライト設定 | |
| " autocmd ColorScheme * highlight CursorWord guifg=#ff8787 | |
| " アンダーラインでハイライトを行う場合 | |
| autocmd ColorScheme * highlight CursorWord gui=underline guifg=#ff8787 | |
| autocmd BufLeave * call s:hl_clear() | |
| autocmd WinLeave * call s:hl_clear() | |
| autocmd InsertEnter * call s:hl_clear() | |
| augroup END | |
| function! s:hl_clear() | |
| if exists("b:highlight_cursor_word_id") && exists("b:highlight_cursor_word") | |
| silent! call matchdelete(b:highlight_cursor_word_id) | |
| unlet b:highlight_cursor_word_id | |
| unlet b:highlight_cursor_word | |
| endif | |
| endfunction | |
| function! s:hl_cword() | |
| let cursorChar = matchstr(getline('.'), '.', col('.')-1) | |
| if matchstr(cursorChar,"[a-zA-Z0-9_'.]") != "" | |
| let word = expand('<cword>') | |
| else | |
| let word = expand('<cWORD>') | |
| endif | |
| if word == "" | |
| return | |
| endif | |
| if get(b:, "highlight_cursor_word", "") ==# word | |
| return | |
| endif | |
| call s:hl_clear() | |
| if !g:enable_highlight_cursor_word | |
| return | |
| endif | |
| if !empty(filter(split(word, '\zs'), "strlen(v:val) > 1")) | |
| return | |
| endif | |
| silent! let b:highlight_cursor_word_id = matchadd("CursorWord", word) | |
| let b:highlight_cursor_word = word | |
| endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment