From a3719c30a7b18f15973d4eab5227147542725480 Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Fri, 23 Aug 2019 23:37:18 +0800 Subject: [PATCH] Improve: make ctrlp layer works better (#3015) --- autoload/SpaceVim/layers/ctrlp.vim | 175 +++++++++++++++++++++++++--- autoload/SpaceVim/layers/denite.vim | 4 +- docs/cn/layers/ctrlp.md | 4 +- docs/cn/layers/denite.md | 1 + docs/layers/ctrlp.md | 4 +- 5 files changed, 166 insertions(+), 22 deletions(-) diff --git a/autoload/SpaceVim/layers/ctrlp.vim b/autoload/SpaceVim/layers/ctrlp.vim index 4c1086b49..f91ca2651 100644 --- a/autoload/SpaceVim/layers/ctrlp.vim +++ b/autoload/SpaceVim/layers/ctrlp.vim @@ -13,34 +13,92 @@ function! SpaceVim#layers#ctrlp#plugins() abort \ ['mattn/ctrlp-register', {'on_cmd' : 'CtrlPRegister'}], \ ['DeaR/ctrlp-jumps', {'on_cmd' : 'CtrlPJump'}], \ ['SpaceVim/vim-ctrlp-help', {'on_cmd' : 'CtrlPHelp'}], + \ ['hara/ctrlp-colorscheme', {'on_cmd' : 'CtrlPColorscheme'}], \ ] + call add(plugins, ['wsdjeg/ctrlp-menu', {'merged' : 0}]) + call add(plugins, ['Shougo/neoyank.vim', {'merged' : 0}]) + call add(plugins, ['wsdjeg/ctrlp-yank', {'merged' : 0}]) return plugins endfunction let s:filename = expand(':~') let s:lnum = expand('') + 2 function! SpaceVim#layers#ctrlp#config() abort - call SpaceVim#mapping#space#def('nnoremap', ['f', 'r'], 'CtrlPMRU', 'open-recent-file', 1) - call SpaceVim#mapping#space#def('nnoremap', ['h', 'i'], 'call call(' - \ . string(s:_function('s:get_help_with_cursor_symbol')) . ', [])', - \ 'get help with the symbol at point', 1) + let lnum = expand('') + s:lnum - 1 - call SpaceVim#mapping#space#def('nnoremap', ['p', 'f'], - \ 'CtrlP', - \ ['find files in current project', + call SpaceVim#mapping#space#def('nnoremap', ['?'], 'call call(' + \ . string(s:_function('s:get_menu')) . ', ["CustomKeyMaps", "[SPC]"])', + \ ['show mappings', \ [ - \ '[SPC p f] is to find files in the root of the current project', + \ '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) - call SpaceVim#mapping#space#def('nnoremap', ['j', 'i'], 'Denite outline', 'jump to a definition in buffer', 1) - " This is definded in plugin config - " nnoremap :Ctrlp - call SpaceVim#mapping#space#def('nnoremap', ['T', 's'], 'Denite colorscheme', 'fuzzy find colorschemes', 1) - let g:_spacevim_mappings.f = {'name' : '+Fuzzy Finder'} - call s:defind_fuzzy_finder() + \ ], + \ 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', + \ ['buffer-list', + \ [ + \ '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 a 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')", @@ -52,6 +110,36 @@ function! SpaceVim#layers#ctrlp#config() abort \ ] \ ] \ , 1) + + let lnum = expand('') + s:lnum - 1 + call SpaceVim#mapping#space#def('nnoremap', ['p', 'f'], + \ 'CtrlP', + \ ['find files in current 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 with the symbol at point', + \ [ + \ '[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 @@ -61,9 +149,28 @@ function! s:get_help_with_cursor_symbol() abort 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 @@ -75,6 +182,17 @@ function! s:defind_fuzzy_finder() abort \ '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 @@ -86,6 +204,10 @@ function! s:defind_fuzzy_finder() abort \ 'Definition: ' . s:file . ':' . lnum, \ ] \ ] + + "@todo add Leader f l for ctrlp location list + "@todo add Leader f m for ctrlp message + nnoremap fq \ :CtrlPQuickfix let lnum = expand('') + s:unite_lnum - 4 @@ -107,6 +229,29 @@ function! s:defind_fuzzy_finder() abort \ '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 diff --git a/autoload/SpaceVim/layers/denite.vim b/autoload/SpaceVim/layers/denite.vim index 00d49abb5..94b77b580 100644 --- a/autoload/SpaceVim/layers/denite.vim +++ b/autoload/SpaceVim/layers/denite.vim @@ -48,13 +48,15 @@ function! SpaceVim#layers#denite#config() abort \ ] \ ], \ 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'], 'call call(' \ . string(s:_function('s:warp_denite')) . ', ["Denite buffer"])', \ ['buffer-list', \ [ - \ 'SPC b b is to open buffer list via denite', + \ 'SPC b b is to open buffer list', \ '', \ 'Definition: ' . s:filename . ':' . lnum, \ ] diff --git a/docs/cn/layers/ctrlp.md b/docs/cn/layers/ctrlp.md index 873ba7068..3462a634d 100644 --- a/docs/cn/layers/ctrlp.md +++ b/docs/cn/layers/ctrlp.md @@ -37,11 +37,9 @@ ctrlp 模块默认并未启用,如果需要启用该模块,需要在配置 | 快捷键 | 功能描述 | | -------------------- | ------------------------------ | | ` f ` | 模糊查找快捷键,并执行该快捷键 | +| ` f p` | 模糊查找已安装插件 | | ` f e` | 模糊搜索寄存器 | | ` f h` | 模糊搜索 history/yank | | ` f j` | 模糊搜索 jump, change | -| ` f l` | 模糊搜索 location list | -| ` f m` | 模糊搜索 output messages | | ` f o` | 模糊搜索函数列表 | | ` f q` | 模糊搜索 quickfix list | -| ` f r` | 重置上次搜索窗口 | diff --git a/docs/cn/layers/denite.md b/docs/cn/layers/denite.md index 37ba81af1..affd76d96 100644 --- a/docs/cn/layers/denite.md +++ b/docs/cn/layers/denite.md @@ -34,6 +34,7 @@ denite 模块默认并未启用,如果需要启用该模块,需要在配置 | 快捷键 | 功能描述 | | -------------------- | ------------------------------ | | ` f ` | 模糊查找快捷键,并执行该快捷键 | +| ` f p` | 模糊查找已安装插件 | | ` f e` | 模糊搜索寄存器 | | ` f h` | 模糊搜索 history/yank | | ` f j` | 模糊搜索 jump, change | diff --git a/docs/layers/ctrlp.md b/docs/layers/ctrlp.md index da8196da0..80566912f 100644 --- a/docs/layers/ctrlp.md +++ b/docs/layers/ctrlp.md @@ -31,11 +31,9 @@ name = "ctrlp" | Key bindings | Discription | | -------------------- | ----------------------------- | | ` f ` | Fuzzy find menu:CustomKeyMaps | +| ` f p` | Fuzzy find menu:AddedPlugins | | ` f e` | Fuzzy find register | | ` f h` | Fuzzy find history/yank | | ` f j` | Fuzzy find jump, change | -| ` f l` | Fuzzy find location list | -| ` f m` | Fuzzy find output messages | | ` f o` | Fuzzy find outline | | ` f q` | Fuzzy find quick fix | -| ` f r` | Resumes Unite window |