"============================================================================= " incsearch.vim --- SpaceVim incsearch layer " Copyright (c) 2016-2021 Wang Shidong & Contributors " Author: Wang Shidong < wsdjeg at 163.com > " URL: https://spacevim.org " License: GPLv3 "============================================================================= "" " @section incsearch, layers-incsearch " @parentsection layers " This layer improved incremental searching for neovim/vim " " mappings " > " key mode description " / n/v incsearch forward " ? n/v incsearch backward " g/ n/v incsearch stay " n n nohlsearch n " N n nohlsearch N " * n nohlsearch * " g* n nohlsearch g* " # n nohlsearch # " g# n nohlsearch g# " z/ n incsearch fuzzy / " z? n incsearch fuzzy ? " zg? n incsearch fuzzy g? " / n incsearch easymotion " < let s:filename = expand(':~') function! SpaceVim#layers#incsearch#plugins() abort let plugins = [] call add(plugins, [g:_spacevim_root_dir . 'bundle/incsearch.vim', {'merged' : 0}]) call add(plugins, ['haya14busa/incsearch-fuzzy.vim', {'merged' : 0}]) call add(plugins, ['haya14busa/vim-asterisk', {'merged' : 0}]) call add(plugins, ['osyo-manga/vim-over', {'merged' : 0}]) call add(plugins, ['haya14busa/incsearch-easymotion.vim', {'merged' : 0}]) return plugins endfunction function! SpaceVim#layers#incsearch#health() abort call SpaceVim#layers#incsearch#plugins() call SpaceVim#layers#incsearch#config() return 1 endfunction let s:lnum = expand('') + 3 function! SpaceVim#layers#incsearch#config() abort " makes * and # work on visual mode too. map / (incsearch-forward) map ? (incsearch-backward) map g/ (incsearch-stay) set hlsearch let g:incsearch#no_inc_hlsearch = 1 let g:incsearch#auto_nohlsearch = get(g:, 'incsearch#auto_nohlsearch', 1) nnoremap n :call update_search_index('d') nnoremap N :call update_search_index('r') map * (incsearch-nohl-*) map # (incsearch-nohl-#) map g* (incsearch-nohl-g*) map g# (incsearch-nohl-g#) xnoremap * :call visual_star_saerch('/')/=@/ xnoremap # :call visual_star_saerch('?')?=@/ function! s:config_fuzzyall(...) abort return extend(copy({ \ 'converters': [ \ incsearch#config#fuzzy#converter(), \ incsearch#config#fuzzyspell#converter() \ ], \ }), get(a:, 1, {})) endfunction function! s:config_easyfuzzymotion(...) abort return extend(copy({ \ 'converters': [incsearch#config#fuzzy#converter()], \ 'modules': [incsearch#config#easymotion#module({'overwin': 1})], \ 'keymap': {"\": '(easymotion)'}, \ 'is_expr': 0, \ 'is_stay': 1 \ }), get(a:, 1, {})) endfunction let lnum = expand('') + s:lnum - 1 call SpaceVim#mapping#space#def('nmap', ['b', '/'], '(incsearch-fuzzyword-/)', ['fuzzy find word', \ [ \ '[SPC b /] is fuzzy find word in current buffer', \ '', \ 'Definition: ' . s:filename . ':' . lnum, \ ] \ ] \ , 0) endfunction let s:si_flag = 0 function! s:update_search_index(key) abort if a:key ==# 'd' if mapcheck('(incsearch-nohl-n)') !=# '' call feedkeys("\(incsearch-nohl-n)") else normal! n endif elseif a:key ==# 'r' if mapcheck('(incsearch-nohl-N)') !=# '' call feedkeys("\(incsearch-nohl-N)") else normal! N endif endif let save_cursor = getpos('.') if !SpaceVim#layers#core#statusline#check_section('search status') call SpaceVim#layers#core#statusline#toggle_section('search status') endif let &l:statusline = SpaceVim#layers#core#statusline#get(1) keepjumps call setpos('.', save_cursor) endfunction function! s:visual_star_saerch(cmdtype) let temp = @s norm! gv"sy let @/ = '\V' . substitute(escape(@s, a:cmdtype.'\'), '\n', '\\n', 'g') let @s = temp endfunction