1
Fork 0
vim-highlight/plugin/hightlight.vim

106 lines
3.8 KiB
VimL
Raw Normal View History

2017-05-17 07:35:27 +00:00
" ==============================================================================
2016-11-06 19:42:13 +00:00
" File: highlight.vim
" Maintainer: Joshua Potter <jrpotter2112@gmail.com>
"
2017-05-17 07:35:27 +00:00
" ==============================================================================
2016-11-06 19:42:13 +00:00
2016-11-18 23:11:12 +00:00
if exists('g:loaded_highlight_registry')
finish
2016-11-06 19:42:13 +00:00
endif
2016-11-18 23:11:12 +00:00
let g:loaded_highlight_registry = 1
2016-11-06 19:42:13 +00:00
2016-11-07 08:30:51 +00:00
" GLOBAL VARIABLES:
2017-05-17 07:35:27 +00:00
" ==============================================================================
2016-11-06 19:42:13 +00:00
2016-11-18 23:11:12 +00:00
" g:highlight_registry :: { String : String } {{{2
2017-05-17 07:35:27 +00:00
" ------------------------------------------------------------------------------
" The following dictionary corresponds to registers 0-9 and their respective
" colors. Adjust this to set the colors for a given register. If a register
" isn't added to this dictionary before being attempted to be used, one of the
" least most colors will be chosen instead. See *cterm-colors*.
" TODO(jrpotter): Allow for better automatic color choices.
2016-11-18 23:11:12 +00:00
if !exists('g:highlight_registry')
let g:highlight_registry = { '0' : 'Yellow',
\ '1' : 'Blue',
\ '2' : 'Red',
\ '3' : 'Magenta',
\ '4' : 'Green',
\ '5' : 'Cyan',
\ '6' : 'DarkYellow',
\ '7' : 'White',
\ '8' : 'Gray',
\ '9' : 'Black',
\ }
2016-11-18 23:11:12 +00:00
endif
2016-11-06 19:42:13 +00:00
2016-11-18 23:11:12 +00:00
" MAPPINGS: {{{1
2017-05-17 07:35:27 +00:00
" ==============================================================================
let s:word = 'expand("<cword>")'
let s:cword = '\<expand(<cword>)\>'
let s:vword = 'highlight#get_visual_selection()'
2016-11-08 01:06:23 +00:00
2016-11-18 23:11:12 +00:00
" Append Searches
noremap <Plug>HRegistry_AppendToSearch
2017-05-17 07:35:27 +00:00
\ :call highlight#append_to_search(v:register, 'c')<Bar>
\ call highlight#count_pattern(eval(s:cword))<CR>
noremap <Plug>HRegistry_GAppendToSearch
\ :call highlight#append_to_search(v:register, 'g')<Bar>
\ call highlight#count_pattern(eval(s:word))<CR>
2016-11-18 23:11:12 +00:00
noremap <Plug>HRegistry_VisualAppendToSearch
2017-05-17 07:35:27 +00:00
\ :call highlight#append_to_search(v:register, 'v')<Bar>
\ call highlight#count_pattern(eval(s:vword))<CR>
2016-11-18 23:11:12 +00:00
" Remove Searches
noremap <Plug>HRegistry_RemoveFromSearch
2016-11-18 23:38:01 +00:00
\ :call highlight#remove_from_search(v:register, '\<'.expand('<cword>').'\>')<CR>
2016-11-18 23:11:12 +00:00
noremap <Plug>HRegistry_VisualRemoveFromSearch
2016-11-18 23:38:01 +00:00
\ :call highlight#remove_from_search(v:register, highlight#get_visual_selection())<CR>
2016-11-18 23:11:12 +00:00
" Other Modifications
2016-11-18 23:38:01 +00:00
noremap <Plug>HRegistry_ClearRegister
\ :call highlight#clear_register(v:register)<CR>
noremap <Plug>HRegistry_ActivateRegister
\ :call highlight#activate_register(v:register)<CR>
noremap <Plug>HRegistry_CountLastSeen
2017-05-17 07:01:25 +00:00
\ :call highlight#count_pattern('\<'.expand('<cword>').'\>')<CR>
2016-11-18 23:11:12 +00:00
" Normal Mappings
2016-11-18 23:38:01 +00:00
nmap <silent> & <Plug>HRegistry_AppendToSearch
2017-05-17 07:35:27 +00:00
nmap <silent> g& <Plug>HRegistry_GAppendToSearch
2016-11-18 23:38:01 +00:00
nmap <silent> y& <Plug>HRegistry_ActivateRegister
nmap <silent> d& <Plug>HRegistry_RemoveFromSearch
nmap <silent> c& <Plug>HRegistry_ClearRegister
2016-11-18 23:11:12 +00:00
2016-11-18 23:38:01 +00:00
nmap <silent> * :silent norm! *<CR>&
nmap <silent> g* :silent norm! *<CR>g&
2016-11-07 08:30:51 +00:00
2016-11-18 23:38:01 +00:00
nmap <silent> # :silent norm! #<CR>&
nmap <silent> g# :silent norm! #<CR>g&
2016-11-07 08:30:51 +00:00
2016-11-18 23:11:12 +00:00
" Visual Mappings
2016-11-18 23:38:01 +00:00
vmap <silent> & <Plug>HRegistry_VisualAppendToSearch'<
vmap <silent> d& <Plug>HRegistry_VisualRemoveFromSearch'<
vmap <silent> * &n<Plug>HRegistry_CountLastSeen
vmap <silent> # &N<Plug>HRegistry_CountLastSeen
2016-11-06 19:42:13 +00:00
2016-11-07 08:30:51 +00:00
" PROCEDURE: Commands {{1
2017-05-17 07:35:27 +00:00
" ==============================================================================
function! s:ClearHighlightRegistry()
call highlight#clear_all_registers()
endfunction
command ClearHighlightRegistry :call <SID>ClearHighlightRegistry()
2016-11-07 08:30:51 +00:00
" PROCEDURE: Initialize {{{1
2017-05-17 07:35:27 +00:00
" ==============================================================================
2016-11-06 19:42:13 +00:00
call s:ClearHighlightRegistry()
2016-11-18 23:11:12 +00:00
call highlight#append_to_search(v:register, @/)
2016-11-08 01:06:23 +00:00