1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-02 23:10:06 +08:00

Improve: make ctrlp layer works better (#3015)

This commit is contained in:
Wang Shidong 2019-08-23 23:37:18 +08:00 committed by GitHub
parent 57fed587d3
commit a3719c30a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 166 additions and 22 deletions

View File

@ -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('<sfile>:~')
let s:lnum = expand('<slnum>') + 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('<slnum>') + 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('<slnum>') + 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 <silent> <C-p> :Ctrlp<cr>
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 <Space>h<Space> [SPC]h[SPC]
let lnum = expand('<slnum>') + 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('<slnum>') + 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('<slnum>') + 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('<slnum>') + 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('<slnum>') + 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('<slnum>') + 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 <silent> <C-p> :Ctrlp<cr>
let lnum = expand('<slnum>') + 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('<sfile>:~')
let s:unite_lnum = expand('<slnum>') + 3
function! s:defind_fuzzy_finder() abort
"@todo add Leader f r for resume ctrlp
nnoremap <silent> <Leader>fe
\ :<C-u>CtrlPRegister<CR>
let lnum = expand('<slnum>') + s:unite_lnum - 4
@ -75,6 +182,17 @@ function! s:defind_fuzzy_finder() abort
\ 'Definition: ' . s:file . ':' . lnum,
\ ]
\ ]
nnoremap <silent> <Leader>fh
\ :<C-u>CtrlPNeoyank<CR>
let lnum = expand('<slnum>') + 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 <silent> <Leader>fj
\ :<C-u>CtrlPJump<CR>
let lnum = expand('<slnum>') + 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 <silent> <Leader>fq
\ :<C-u>CtrlPQuickfix<CR>
let lnum = expand('<slnum>') + s:unite_lnum - 4
@ -107,6 +229,29 @@ function! s:defind_fuzzy_finder() abort
\ 'Definition: ' . s:file . ':' . lnum,
\ ]
\ ]
nnoremap <silent> <Leader>f<Space> :CtrlPMenu CustomKeyMaps<CR>
let lnum = expand('<slnum>') + 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 <silent> <Leader>fp :<C-u>CtrlPMenu AddedPlugins<CR>
let lnum = expand('<slnum>') + 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

View File

@ -48,13 +48,15 @@ function! SpaceVim#layers#denite#config() abort
\ ]
\ ],
\ 1)
" @fixme SPC h SPC make vim flick
nmap <Space>h<Space> [SPC]h[SPC]
let lnum = expand('<slnum>') + 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,
\ ]

View File

@ -37,11 +37,9 @@ ctrlp 模块默认并未启用,如果需要启用该模块,需要在配置
| 快捷键 | 功能描述 |
| -------------------- | ------------------------------ |
| `<Leader> f <Space>` | 模糊查找快捷键,并执行该快捷键 |
| `<Leader> f p` | 模糊查找已安装插件 |
| `<Leader> f e` | 模糊搜索寄存器 |
| `<Leader> f h` | 模糊搜索 history/yank |
| `<Leader> f j` | 模糊搜索 jump, change |
| `<Leader> f l` | 模糊搜索 location list |
| `<Leader> f m` | 模糊搜索 output messages |
| `<Leader> f o` | 模糊搜索函数列表 |
| `<Leader> f q` | 模糊搜索 quickfix list |
| `<Leader> f r` | 重置上次搜索窗口 |

View File

@ -34,6 +34,7 @@ denite 模块默认并未启用,如果需要启用该模块,需要在配置
| 快捷键 | 功能描述 |
| -------------------- | ------------------------------ |
| `<Leader> f <Space>` | 模糊查找快捷键,并执行该快捷键 |
| `<Leader> f p` | 模糊查找已安装插件 |
| `<Leader> f e` | 模糊搜索寄存器 |
| `<Leader> f h` | 模糊搜索 history/yank |
| `<Leader> f j` | 模糊搜索 jump, change |

View File

@ -31,11 +31,9 @@ name = "ctrlp"
| Key bindings | Discription |
| -------------------- | ----------------------------- |
| `<Leader> f <Space>` | Fuzzy find menu:CustomKeyMaps |
| `<Leader> f p` | Fuzzy find menu:AddedPlugins |
| `<Leader> f e` | Fuzzy find register |
| `<Leader> f h` | Fuzzy find history/yank |
| `<Leader> f j` | Fuzzy find jump, change |
| `<Leader> f l` | Fuzzy find location list |
| `<Leader> f m` | Fuzzy find output messages |
| `<Leader> f o` | Fuzzy find outline |
| `<Leader> f q` | Fuzzy find quick fix |
| `<Leader> f r` | Resumes Unite window |