"============================================================================= " fuzzy.vim --- fuzzy layer of SpaceVim " Copyright (c) 2016-2023 Wang Shidong & Contributors " Author: Wang Shidong < wsdjeg@outlook.com > " URL: https://spacevim.org " License: GPLv3 "============================================================================= function! SpaceVim#layers#fuzzy#plugins() abort let plugins = [ \ ['wsdjeg/vim-fuzzy-search', {'loadconf' : 1, 'merged' : 0}], \ ] call add(plugins, [g:_spacevim_root_dir . 'bundle/neoyank.vim', {'merged' : 0}]) return plugins endfunction function! SpaceVim#layers#fuzzy#health() abort call SpaceVim#layers#fuzzy#plugins() call SpaceVim#layers#fuzzy#config() return 1 endfunction let s:filename = expand(':~') let s:lnum = expand('') + 2 function! SpaceVim#layers#fuzzy#config() abort let lnum = expand('') + s:lnum - 1 call SpaceVim#mapping#space#def('nnoremap', ['?'], 'call call(' \ . string(s:_function('s:get_menu')) . ', ["CustomKeyMaps", "[SPC]"])', \ ['show-mappings', \ [ \ 'SPC ? is to show mappings', \ '', \ 'Definition: ' . s:filename . ':' . lnum, \ ] \ ], \ 1) let lnum = expand('') + s:lnum - 1 call SpaceVim#mapping#space#def('nnoremap', ['h', '[SPC]'], 'call call(' \ . string(s:_function('s:get_help')) . ', ["SpaceVim"])', \ ['find-SpaceVim-help', \ [ \ 'SPC h SPC is to find SpaceVim help', \ '', \ 'Definition: ' . s:filename . ':' . lnum, \ ] \ ], \ 1) " @fixme SPC h SPC make vim flick nmap h [SPC]h[SPC] let lnum = expand('') + s:lnum - 1 call SpaceVim#mapping#space#def('nnoremap', ['b', 'b'], 'CtrlPBuffer', \ ['list-buffer', \ [ \ 'SPC b b is to open buffer list', \ '', \ 'Definition: ' . s:filename . ':' . lnum, \ ] \ ], \ 1) let lnum = expand('') + s:lnum - 1 call SpaceVim#mapping#space#def('nnoremap', ['f', 'r'], 'CtrlPMRU', \ ['open-recent-file', \ [ \ 'SPC f r is to open recent file list', \ '', \ 'Definition: ' . s:filename . ':' . lnum, \ ] \ ], \ 1) let lnum = expand('') + s:lnum - 1 call SpaceVim#mapping#space#def('nnoremap', ['j', 'i'], 'CtrlPBufTag', \ ['jump-to-definition-in-buffer', \ [ \ 'SPC j i is to jump to a definition in buffer', \ '', \ 'Definition: ' . s:filename . ':' . lnum, \ ] \ ], \ 1) "@todo add resume support for ctrlp: SPC r l "@fixme ctrlp colorschemes support let lnum = expand('') + s:lnum - 1 call SpaceVim#mapping#space#def('nnoremap', ['T', 's'], 'CtrlPColorscheme', \ ['fuzzy-find-colorschemes', \ [ \ 'SPC T s is to fuzzy find colorschemes', \ '', \ 'Definition: ' . s:filename . ':' . lnum, \ ] \ ], \ 1) let lnum = expand('') + s:lnum - 1 call SpaceVim#mapping#space#def('nnoremap', ['f', 'f'], \ "exe 'CtrlP ' . fnamemodify(bufname('%'), ':h')", \ ['find-files-in-buffer-directory', \ [ \ '[SPC f f] is to find files in the directory of the current buffer', \ '', \ 'Definition: ' . s:filename . ':' . lnum, \ ] \ ] \ , 1) let lnum = expand('') + s:lnum - 1 call SpaceVim#mapping#space#def('nnoremap', ['p', 'f'], \ 'CtrlP', \ ['find-files-in-project', \ [ \ '[SPC p f] is to find files in the root of the current project', \ '', \ 'Definition: ' . s:filename . ':' . lnum, \ ] \ ] \ , 1) " This is definded in plugin config " nnoremap :Ctrlp let lnum = expand('') + s:lnum - 1 call SpaceVim#mapping#space#def('nnoremap', ['h', 'i'], 'call call(' \ . string(s:_function('s:get_help_with_cursor_symbol')) . ', [])', \ ['get-help-for-cursor-symbol', \ [ \ '[SPC h i] is to get help with the symbol at point', \ '', \ 'Definition: ' . s:filename . ':' . lnum, \ ] \ ], \ 1) let g:_spacevim_mappings.f = {'name' : '+Fuzzy Finder'} call s:defind_fuzzy_finder() endfunction function! s:get_help_with_cursor_symbol() abort let save_ctrlp_default_input = get(g:, 'ctrlp_default_input', '') let g:ctrlp_default_input = expand('') CtrlPHelp let g:ctrlp_default_input = save_ctrlp_default_input endfunction function! s:get_help(word) abort let save_ctrlp_default_input = get(g:, 'ctrlp_default_input', '') let g:ctrlp_default_input = a:word CtrlPHelp let g:ctrlp_default_input = save_ctrlp_default_input endfunction function! s:get_menu(menu, input) abort let save_ctrlp_default_input = get(g:, 'ctrlp_default_input', '') let g:ctrlp_default_input = a:input exe 'CtrlPMenu ' . a:menu let g:ctrlp_default_input = save_ctrlp_default_input endfunction let s:file = expand(':~') let s:unite_lnum = expand('') + 3 function! s:defind_fuzzy_finder() abort "@todo add Leader f r for resume ctrlp nnoremap fe \ :CtrlPRegister let lnum = expand('') + s:unite_lnum - 4 let g:_spacevim_mappings.f.e = ['CtrlPRegister', \ 'fuzzy find registers', \ [ \ '[Leader f r ] is to resume unite window', \ '', \ 'Definition: ' . s:file . ':' . lnum, \ ] \ ] nnoremap fh \ :CtrlPNeoyank let lnum = expand('') + s:unite_lnum - 4 let g:_spacevim_mappings.f.h = ['CtrlPNeoyank', \ 'fuzzy find yank history', \ [ \ '[Leader f h] is to fuzzy find history and yank content', \ '', \ 'Definition: ' . s:file . ':' . lnum, \ ] \ ] nnoremap fj \ :CtrlPJump let lnum = expand('') + s:unite_lnum - 4 let g:_spacevim_mappings.f.j = ['CtrlPJump', \ 'fuzzy find jump list', \ [ \ '[Leader f j] is to fuzzy find jump list', \ '', \ 'Definition: ' . s:file . ':' . lnum, \ ] \ ] "@todo add Leader f l for ctrlp location list nnoremap fm \ :CtrlPMessage let lnum = expand('') + s:unite_lnum - 4 let g:_spacevim_mappings.f.m = ['CtrlPMessage', \ 'fuzzy find and yank message history', \ [ \ '[Leader f m] is to fuzzy find and yank message history', \ '', \ 'Definition: ' . s:file . ':' . lnum, \ ] \ ] nnoremap fq \ :CtrlPQuickfix let lnum = expand('') + s:unite_lnum - 4 let g:_spacevim_mappings.f.q = ['CtrlPQuickfix', \ 'fuzzy find quickfix list', \ [ \ '[Leader f q] is to fuzzy find quickfix list', \ '', \ 'Definition: ' . s:file . ':' . lnum, \ ] \ ] nnoremap fo :CtrlPBufTag let lnum = expand('') + s:unite_lnum - 4 let g:_spacevim_mappings.f.o = ['CtrlPBufTag', \ 'fuzzy find outline', \ [ \ '[Leader f o] is to fuzzy find outline', \ '', \ 'Definition: ' . s:file . ':' . lnum, \ ] \ ] nnoremap f :CtrlPMenu CustomKeyMaps let lnum = expand('') + s:unite_lnum - 4 let g:_spacevim_mappings.f['[SPC]'] = ['CtrlPMenu CustomKeyMaps', \ 'fuzzy find custom key bindings', \ [ \ '[Leader f SPC] is to fuzzy find custom key bindings', \ '', \ 'Definition: ' . s:file . ':' . lnum, \ ] \ ] nnoremap fp :CtrlPMenu AddedPlugins let lnum = expand('') + s:unite_lnum - 4 let g:_spacevim_mappings.f.p = ['CtrlPMenu AddedPlugins', \ 'fuzzy find vim packages', \ [ \ '[Leader f p] is to fuzzy find vim packages installed in SpaceVim', \ '', \ 'Definition: ' . s:file . ':' . lnum, \ ] \ ] endfunction " function() wrapper if v:version > 703 || v:version == 703 && has('patch1170') function! s:_function(fstr) abort return function(a:fstr) endfunction else function! s:_SID() abort return matchstr(expand(''), '\zs\d\+\ze__SID$') endfunction let s:_s = '' . s:_SID() . '_' function! s:_function(fstr) abort return function(substitute(a:fstr, 's:', s:_s, 'g')) endfunction endif