Merge pull request #20 from junegunn/mappings
Add mapping selecting mappings
This commit is contained in:
commit
813796a204
4 changed files with 77 additions and 0 deletions
11
README.md
11
README.md
|
@ -66,6 +66,7 @@ Commands
|
|||
| `Commits` | Git commits (requires [fugitive.vim][f]) |
|
||||
| `BCommits` | Git commits for the current buffer |
|
||||
| `Commands` | Commands |
|
||||
| `Maps` | Normal mode mappings |
|
||||
| `Helptags` | Help tags <sup id="a1">[1](#helptags)</sup> |
|
||||
|
||||
- Most commands support `CTRL-T` / `CTRL-X` / `CTRL-V` key
|
||||
|
@ -103,6 +104,10 @@ Mappings
|
|||
|
||||
| Mapping | Description |
|
||||
| --- | --- |
|
||||
| `<plug>(fzf-maps-n)` | Normal mode mappings |
|
||||
| `<plug>(fzf-maps-i)` | Insert mode mappings |
|
||||
| `<plug>(fzf-maps-x)` | Visual mode mappings |
|
||||
| `<plug>(fzf-maps-o)` | Operator-pending mappings |
|
||||
| `<plug>(fzf-complete-word)` | `cat /usr/share/dict/words` |
|
||||
| `<plug>(fzf-complete-path)` | Path completion using `find` (file + dir) |
|
||||
| `<plug>(fzf-complete-file)` | File completion using `find` |
|
||||
|
@ -113,6 +118,12 @@ Mappings
|
|||
### Usage
|
||||
|
||||
```vim
|
||||
" Mapping selecting mappings
|
||||
nmap <leader><tab> <plug>(fzf-maps-n)
|
||||
xmap <leader><tab> <plug>(fzf-maps-x)
|
||||
omap <leader><tab> <plug>(fzf-maps-o)
|
||||
|
||||
" Insert mode completion
|
||||
imap <c-x><c-k> <plug>(fzf-complete-word)
|
||||
imap <c-x><c-f> <plug>(fzf-complete-path)
|
||||
imap <c-x><c-j> <plug>(fzf-complete-file-ag)
|
||||
|
|
|
@ -711,6 +711,55 @@ function! fzf#vim#buffer_commits(...)
|
|||
return s:commits(1, a:000)
|
||||
endfunction
|
||||
|
||||
" ------------------------------------------------------------------
|
||||
" fzf#vim#maps(mode, opts[with count and op])
|
||||
" ------------------------------------------------------------------
|
||||
function! s:align_pairs(list)
|
||||
let maxlen = 0
|
||||
let pairs = []
|
||||
for elem in a:list
|
||||
let match = matchlist(elem, '^\(\S*\)\s*\(.*\)$')
|
||||
let [_, k, v] = match[0:2]
|
||||
let maxlen = max([maxlen, len(k)])
|
||||
call add(pairs, [k, v])
|
||||
endfor
|
||||
return map(pairs, "printf('%-'.maxlen.'s', v:val[0]).' '.v:val[1]")
|
||||
endfunction
|
||||
|
||||
function! s:highlight_keys(str)
|
||||
return substitute(
|
||||
\ substitute(a:str, '<[^ >]\+>', "\x1b[33m\\0\x1b[m", 'g'),
|
||||
\ "\x1b[33m<Plug>\x1b[m", "\x1b[34m<Plug>\x1b[m", 'g')
|
||||
endfunction
|
||||
|
||||
function! s:key_sink(line)
|
||||
let key = matchstr(a:line, '^\S*')
|
||||
redraw
|
||||
call feedkeys(s:map_gv.s:map_cnt.s:map_reg.s:map_op.
|
||||
\ substitute(key, '<[^ >]\+>', '\=eval("\"\\".submatch(0)."\"")', 'g'))
|
||||
endfunction
|
||||
|
||||
" To avoid conflict with other plugins also using feedkeys (peekaboo)
|
||||
noremap <plug>(-fzf-vim-dq) "
|
||||
|
||||
function! fzf#vim#maps(mode, ...)
|
||||
let s:map_gv = a:mode == 'x' ? 'gv' : ''
|
||||
let s:map_cnt = v:count == 0 ? '' : v:count
|
||||
let s:map_reg = empty(v:register) ? '' : ("\<plug>(-fzf-vim-dq)".v:register)
|
||||
let s:map_op = a:mode == 'o' ? v:operator : ''
|
||||
redir => cout
|
||||
silent execute a:mode.'map'
|
||||
redir END
|
||||
let list = map(split(cout, "\n"), 'v:val[3:]')
|
||||
let aligned = s:align_pairs(map(split(cout, "\n"), 'v:val[3:]'))
|
||||
let sorted = sort(aligned)
|
||||
let colored = map(sorted, 's:highlight_keys(v:val)')
|
||||
call s:fzf({
|
||||
\ 'source': colored,
|
||||
\ 'sink': function('s:key_sink'),
|
||||
\ 'options': '--ansi --no-hscroll --nth 1,..'}, a:000)
|
||||
endfunction
|
||||
|
||||
" ----------------------------------------------------------------------------
|
||||
" fzf#vim#complete - completion helper
|
||||
" ----------------------------------------------------------------------------
|
||||
|
|
|
@ -92,6 +92,7 @@ COMMANDS *fzf-vim-commands*
|
|||
`Commits` | Git commits (requires {fugitive.vim}{7})
|
||||
`BCommits` | Git commits for the current buffer
|
||||
`Commands` | Commands
|
||||
`Maps` | Normal mode mappings
|
||||
`Helptags` | Help tags [1]
|
||||
-----------------+---------------------------------------------------------------------
|
||||
|
||||
|
@ -135,6 +136,10 @@ MAPPINGS *fzf-vim-mappings*
|
|||
---------------------------------+------------------------------------------
|
||||
Mapping | Description ~
|
||||
---------------------------------+------------------------------------------
|
||||
<plug>(fzf-maps-n) | Normal mode mappings
|
||||
<plug>(fzf-maps-i) | Insert mode mappings
|
||||
<plug>(fzf-maps-x) | Visual mode mappings
|
||||
<plug>(fzf-maps-o) | Operator-pending mappings
|
||||
<plug>(fzf-complete-word) | `cat /usr/share/dict/words`
|
||||
<plug>(fzf-complete-path) | Path completion using `find` (file + dir)
|
||||
<plug>(fzf-complete-file) | File completion using `find`
|
||||
|
@ -147,6 +152,12 @@ MAPPINGS *fzf-vim-mappings*
|
|||
< Usage >_____________________________________________________________________~
|
||||
*fzf-vim-usage*
|
||||
>
|
||||
" Mapping selecting mappings
|
||||
nmap <leader><tab> <plug>(fzf-maps-n)
|
||||
xmap <leader><tab> <plug>(fzf-maps-x)
|
||||
omap <leader><tab> <plug>(fzf-maps-o)
|
||||
|
||||
" Insert mode completion
|
||||
imap <c-x><c-k> <plug>(fzf-complete-word)
|
||||
imap <c-x><c-f> <plug>(fzf-complete-path)
|
||||
imap <c-x><c-j> <plug>(fzf-complete-file-ag)
|
||||
|
|
|
@ -58,6 +58,7 @@ call s:defs([
|
|||
\'command! -bang Windows call fzf#vim#windows(s:w(<bang>0))',
|
||||
\'command! -bang Commits call fzf#vim#commits(s:w(<bang>0))',
|
||||
\'command! -bang BCommits call fzf#vim#buffer_commits(s:w(<bang>0))',
|
||||
\'command! -bang Maps call fzf#vim#maps("n", s:w(<bang>0))',
|
||||
\'command! -bang -nargs=* History call s:history(<q-args>, <bang>0)'])
|
||||
|
||||
function! s:history(arg, bang)
|
||||
|
@ -112,6 +113,11 @@ inoremap <expr> <plug>(fzf-complete-file-ag) fzf#vim#complete#path("ag -l -g
|
|||
inoremap <expr> <plug>(fzf-complete-line) fzf#vim#complete#line()
|
||||
inoremap <expr> <plug>(fzf-complete-buffer-line) fzf#vim#complete#buffer_line()
|
||||
|
||||
nnoremap <silent> <plug>(fzf-maps-n) :<c-u>call fzf#vim#maps('n', <sid>w(0))<cr>
|
||||
inoremap <silent> <plug>(fzf-maps-i) <c-o>:call fzf#vim#maps('i', <sid>w(0))<cr>
|
||||
xnoremap <silent> <plug>(fzf-maps-x) :<c-u>call fzf#vim#maps('x', <sid>w(0))<cr>
|
||||
onoremap <silent> <plug>(fzf-maps-o) <c-c>:<c-u>call fzf#vim#maps('o', <sid>w(0))<cr>
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue