dotfiles

<-- duh.
git clone https://hhvn.uk/dotfiles
git clone git://hhvn.uk/dotfiles
Log | Files | Refs | Submodules | LICENSE

quick_scope.vim (5634B)


      1 " Initialize -----------------------------------------------------------------
      2 let s:plugin_name = 'quick-scope'
      3 
      4 if exists('g:loaded_quick_scope')
      5   finish
      6 endif
      7 
      8 let g:loaded_quick_scope = 1
      9 
     10 if &compatible
     11   echoerr s:plugin_name . " won't load in Vi-compatible mode."
     12   finish
     13 endif
     14 
     15 if v:version < 701 || (v:version == 701 && !has('patch040'))
     16   echoerr s:plugin_name . ' requires Vim running in version 7.1.040 or later.'
     17   finish
     18 endif
     19 
     20 " Save cpoptions and reassign them later. See :h use-cpo-save.
     21 let s:cpo_save = &cpo
     22 set cpo&vim
     23 
     24 " Autocommands ---------------------------------------------------------------
     25 augroup quick_scope
     26   autocmd!
     27   autocmd ColorScheme * call s:set_highlight_colors()
     28 augroup END
     29 
     30 " Options --------------------------------------------------------------------
     31 if !exists('g:qs_enable')
     32   let g:qs_enable = 1
     33 endif
     34 
     35 if !exists('g:qs_lazy_highlight')
     36   let g:qs_lazy_highlight = 0
     37 endif
     38 
     39 if !exists('g:qs_max_chars')
     40   " Disable on long lines for performance
     41   let g:qs_max_chars = 1000
     42 endif
     43 
     44 if !exists('g:qs_accepted_chars')
     45   let g:qs_accepted_chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
     46 endif
     47 
     48 if !exists('g:qs_buftype_blacklist')
     49   let g:qs_buftype_blacklist = []
     50 endif
     51 
     52 if !exists('g:qs_highlight_on_keys')
     53   " Vanilla mode. Highlight on cursor movement.
     54   augroup quick_scope
     55     if g:qs_lazy_highlight
     56       autocmd CursorHold,InsertLeave,ColorScheme,WinEnter,BufEnter,FocusGained * call quick_scope#UnhighlightLine() | call quick_scope#HighlightLine(2, g:qs_accepted_chars)
     57     else
     58       autocmd CursorMoved,InsertLeave,ColorScheme,WinEnter,BufEnter,FocusGained * call quick_scope#UnhighlightLine() | call quick_scope#HighlightLine(2, g:qs_accepted_chars)
     59     endif
     60     autocmd InsertEnter,BufLeave,TabLeave,WinLeave,FocusLost * call quick_scope#UnhighlightLine()
     61   augroup END
     62 else
     63   " Highlight on key press. Set an 'augmented' mapping for each defined key.
     64   for motion in filter(g:qs_highlight_on_keys, "v:val =~# '^[fFtT]$'")
     65     for mapmode in ['nnoremap', 'onoremap', 'xnoremap']
     66       execute printf(mapmode . ' <unique> <silent> <expr> %s quick_scope#Ready() . quick_scope#Aim("%s") . quick_scope#Reload() . quick_scope#DoubleTap()', motion, motion)
     67     endfor
     68   endfor
     69 endif
     70 
     71 " User commands --------------------------------------------------------------
     72 command! -nargs=0 QuickScopeToggle call quick_scope#Toggle()
     73 
     74 " Plug mappings --------------------------------------------------------------
     75 nnoremap <silent> <plug>(QuickScopeToggle) :call quick_scope#Toggle()<cr>
     76 xnoremap <silent> <plug>(QuickScopeToggle) :<c-u>call quick_scope#Toggle()<cr>
     77 
     78 " Colors ---------------------------------------------------------------------
     79 " Set the colors used for highlighting.
     80 function! s:set_highlight_colors()
     81   " Priority for overruling other highlight matches.
     82   let g:qs_hi_priority = 1
     83 
     84   " Highlight group marking first appearance of characters in a line.
     85   let g:qs_hi_group_primary = 'QuickScopePrimary'
     86   " Highlight group marking second appearance of characters in a line.
     87   let g:qs_hi_group_secondary = 'QuickScopeSecondary'
     88   " Highlight group marking dummy cursor when quick-scope is enabled on key
     89   " press.
     90   let g:qs_hi_group_cursor = 'QuickScopeCursor'
     91 
     92   if exists('g:qs_first_occurrence_highlight_color')
     93     " backwards compatibility mode for old highlight configuration
     94     augroup quick_scope_lazy_print
     95       if has('vim_starting')
     96         " register this as a lazy print error so as not to block Vim starting
     97         autocmd CursorHold,CursorHoldI * call quick_scope#lazy_print#err('option g:qs_first_occurrence_highlight_color is deprecated!')
     98       else
     99         echohl ErrorMsg
    100         echomsg s:plugin_name . ' option g:qs_first_occurrence_highlight_color is deprecated!'
    101         echohl None
    102       endif
    103     augroup END
    104 
    105     let l:first_color = g:qs_first_occurrence_highlight_color
    106     if l:first_color =~# '#'
    107       execute 'highlight default ' . g:qs_hi_group_primary . ' gui=underline guifg=' . l:first_color
    108     else
    109       execute 'highlight default ' . g:qs_hi_group_primary . ' cterm=underline ctermfg=' . l:first_color
    110     endif
    111   else
    112     execute 'highlight default link ' . g:qs_hi_group_primary . ' Function'
    113   endif
    114 
    115   if exists('g:qs_second_occurrence_highlight_color')
    116     " backwards compatibility mode for old highlight configuration
    117     augroup quick_scope_lazy_print
    118       if has('vim_starting')
    119         " register this as a lazy print error so as not to block Vim starting
    120         autocmd CursorHold,CursorHoldI * call quick_scope#lazy_print#err('option g:qs_second_occurrence_highlight_color is deprecated!')
    121       else
    122         echohl ErrorMsg
    123         echomsg s:plugin_name . ' option g:qs_second_occurrence_highlight_color is deprecated!'
    124         echohl None
    125       endif
    126     augroup END
    127 
    128     let l:second_color = g:qs_second_occurrence_highlight_color
    129     if l:second_color =~# '#'
    130       execute 'highlight default ' . g:qs_hi_group_secondary . ' gui=underline guifg=' . l:second_color
    131     else
    132       execute 'highlight default ' . g:qs_hi_group_secondary . ' cterm=underline ctermfg=' . l:second_color
    133     endif
    134   else
    135     execute 'highlight default link ' . g:qs_hi_group_secondary . ' Define'
    136   endif
    137 
    138   execute 'highlight default link ' . g:qs_hi_group_cursor . ' Cursor'
    139 endfunction
    140 
    141 call s:set_highlight_colors()
    142 
    143 let &cpo = s:cpo_save
    144 unlet s:cpo_save