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

156 lines
5.7 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
" g:highlight_registry :: { String : { String : String } } {{{2
2017-05-17 07:35:27 +00:00
" ------------------------------------------------------------------------------
" The following dictionary corresponds to registers 0-9 and their respective
" syntax attributes. Adjust this to set the properties for a given highlight
" group. Allowed keys in the nested dictionary are listed in *synIDattr*, except
" for the 'name' attribute. Unrecognized keys are simply ignored. Only 'cterm'
" related attributes are supported (that is, gui specific attributes are not
" supported).
"
" In addition, can also include a key of 'group' in the nested dictionary to
" indicate which highlight group to default a property to. By default, this
" group is 'Search'. Thus, key '0' could also be written as:
" { 'fg' : 'Yellow', 'group' : 'Search', 'bold': '0' }.
"
" TODO(jrpotter): Consider adding support for GUI and term?
2016-11-18 23:11:12 +00:00
if !exists('g:highlight_registry')
function! s:InitializeHighlightRegistry()
let g:highlight_registry = {}
let l:colors = [ 'Yellow', 'Blue', 'Red', 'Magenta', 'Green', 'Cyan',
\ 'DarkYellow', 'White', 'Gray', 'Black' ]
let l:index = 0
while l:index < len(l:colors)
let g:highlight_registry[string(l:index)] =
\{ 'fg' : l:colors[l:index], 'bg' : 'none', 'bold' : '1' }
let l:index = l:index + 1
endwhile
endfunction
call s:InitializeHighlightRegistry()
2016-11-18 23:11:12 +00:00
endif
2016-11-06 19:42:13 +00:00
" g:persist_unnamed_register :: Boolean {{{2
" ------------------------------------------------------------------------------
" Determines how to manage the unnamed register '"'. If set to false, we regard
" the unnamed register to implicitly imply use of the last activated register.
if !exists('g:persist_unnamed_register')
let g:persist_unnamed_register = 0
endif
2017-05-24 04:21:13 +00:00
" FUNCTION: ExpandRegister(reg) {{{1
" ==============================================================================
" Convenience method to determine which register is being currently used.
" The unnamed register defaults to the last used register to avoid having to
" constantly prefix registration. This can be changed by setting the value of
" g:persist_unnamed_register to 1.
function! s:ExpandRegister(reg)
if !g:persist_unnamed_register && a:reg ==# '"'
return s:active_register
endif
return a:reg
endfunction
" FUNCTION: ExpandFlag(flag) {{{1
" ==============================================================================
" Convenience method used to make the mappings in plugin/highlight.vim a bit
" easier to read through. The passed flag can be:
"
" c: Indicates the current word, with word boundary.
" g: Indicates the current word, without word boundary.
" v: Indicates the current visual selection.
"
" Throws an error otherwise.
function! s:ExpandFlag(flag) abort
if a:flag ==# 'c'
return '\<' . expand('<cword>') . '\>'
elseif a:flag ==# 'g'
return expand('<cword>')
elseif a:flag ==# 'v'
return highlight#get_visual_selection()
endif
throw 'Could not expand passed flag: ' . a:flag
endfunction
2016-11-18 23:11:12 +00:00
" MAPPINGS: {{{1
2017-05-17 07:35:27 +00:00
" ==============================================================================
2016-11-18 23:11:12 +00:00
" Append Searches
noremap <Plug>HRegistry_AppendToSearch
2017-05-24 04:21:13 +00:00
\ :call highlight#append_to_search(s:ExpandRegister(v:register), s:ExpandFlag('c'))<Bar>
\ call highlight#count_pattern(s:ExpandFlag('c'))<CR>
2017-05-17 07:35:27 +00:00
noremap <Plug>HRegistry_GAppendToSearch
2017-05-24 04:21:13 +00:00
\ :call highlight#append_to_search(s:ExpandRegister(v:register), s:ExpandFlag('g'))<Bar>
\ call highlight#count_pattern(s:ExpandFlag('g'))<CR>
2016-11-18 23:11:12 +00:00
noremap <Plug>HRegistry_VisualAppendToSearch
2017-05-24 04:21:13 +00:00
\ :call highlight#append_to_search(s:ExpandRegister(v:register), s:ExpandFlag('v'))<Bar>
\ call highlight#count_pattern(s:ExpandFlag('v'))<CR>
2016-11-18 23:11:12 +00:00
" Remove Searches
noremap <Plug>HRegistry_RemoveFromSearch
2017-05-24 04:21:13 +00:00
\ :call highlight#remove_from_search(s:ExpandRegister(v:register), s:ExpandFlag('c'))<CR>
2016-11-18 23:11:12 +00:00
noremap <Plug>HRegistry_VisualRemoveFromSearch
2017-05-24 04:21:13 +00:00
\ :call highlight#remove_from_search(s:ExpandRegister(v:register), s:ExpandFlag('v'))<CR>
2016-11-18 23:11:12 +00:00
" Other Modifications
2016-11-18 23:38:01 +00:00
noremap <Plug>HRegistry_ClearRegister
2017-05-24 04:21:13 +00:00
\ :call highlight#clear_register(s:ExpandRegister(v:register))<Bar>
\ call highlight#activate_register(s:ExpandRegister(v:register))<CR>
2016-11-18 23:38:01 +00:00
noremap <Plug>HRegistry_ActivateRegister
2017-05-24 04:21:13 +00:00
\ :call highlight#activate_register(s:ExpandRegister(v:register))<CR>
2016-11-18 23:38:01 +00:00
noremap <Plug>HRegistry_CountLastSeen
2017-05-24 04:21:13 +00:00
\ :call highlight#count_pattern(s:ExpandFlag('c'))<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
" ==============================================================================
command ResetHighlightRegistry :call highlight#reset()
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 highlight#reset()