"============================================================================= " FILE: plugin/incsearch.vim " AUTHOR: haya14busa " License: MIT license {{{ " Permission is hereby granted, free of charge, to any person obtaining " a copy of this software and associated documentation files (the " "Software"), to deal in the Software without restriction, including " without limitation the rights to use, copy, modify, merge, publish, " distribute, sublicense, and/or sell copies of the Software, and to " permit persons to whom the Software is furnished to do so, subject to " the following conditions: " " The above copyright notice and this permission notice shall be included " in all copies or substantial portions of the Software. " " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. " }}} "============================================================================= scriptencoding utf-8 " Load Once {{{ if expand('%:p') ==# expand(':p') unlet! g:loaded_incsearch endif if exists('g:loaded_incsearch') finish endif let g:loaded_incsearch = 1 " }}} " Saving 'cpoptions' {{{ let s:save_cpo = &cpo set cpo&vim " }}} " : do not show command in command line noremap (incsearch-forward) incsearch#go({'command': '/'}) noremap (incsearch-backward) incsearch#go({'command': '?'}) noremap (incsearch-stay) incsearch#go({'command': '/', 'is_stay': 1}) " Apply automatic :h :nohlsearch with :h :autocmd " NOTE: " - This mappings doesn't move the cursor, please use this with other " mappings at the same time. " - Make sure calling this mapping __before__ moving commands " e.g. `(incsearch-nohl)n` works but `n(incsearch-nohl)` doesn't " work noremap (incsearch-nohl) incsearch#autocmd#auto_nohlsearch(1) noremap (incsearch-nohl0) incsearch#autocmd#auto_nohlsearch(0) noremap (incsearch-nohl2) incsearch#autocmd#auto_nohlsearch(2) map (incsearch-nohl-n) (incsearch-nohl)(_incsearch-n) map (incsearch-nohl-N) (incsearch-nohl)(_incsearch-N) map (incsearch-nohl-*) (incsearch-nohl)(_incsearch-*) map (incsearch-nohl-#) (incsearch-nohl)(_incsearch-#) map (incsearch-nohl-g*) (incsearch-nohl)(_incsearch-g*) map (incsearch-nohl-g#) (incsearch-nohl)(_incsearch-g#) " These mappings are just alias to default mappings except they won't be " remapped any more noremap (_incsearch-n) g:incsearch#consistent_n_direction && !v:searchforward ? 'N' : 'n' noremap (_incsearch-N) g:incsearch#consistent_n_direction && !v:searchforward ? 'n' : 'N' noremap (_incsearch-*) * noremap (_incsearch-#) # noremap (_incsearch-g*) g* noremap (_incsearch-g#) g# " CommandLine Mapping {{{ let g:incsearch_cli_key_mappings = get(g:, 'incsearch_cli_key_mappings', {}) function! s:key_mapping(lhs, rhs, noremap) abort let g:incsearch_cli_key_mappings[a:lhs] = { \ 'key' : a:rhs, \ 'noremap' : a:noremap, \ } endfunction function! s:as_keymapping(key) abort return eval('"' . substitute(escape(a:key, '\"'), '\(<.\{-}>\)', '\\\1', 'g') . '"') endfunction command! -nargs=* IncSearchNoreMap \ call call('s:key_mapping', map([], 's:as_keymapping(v:val)') + [1]) command! -nargs=* IncSearchMap \ call call('s:key_mapping', map([], 's:as_keymapping(v:val)') + [0]) "}}} " Restore 'cpoptions' {{{ let &cpo = s:save_cpo unlet s:save_cpo " }}} " __END__ {{{ " vim: expandtab softtabstop=2 shiftwidth=2 " vim: foldmethod=marker " }}}