diff --git a/README.md b/README.md index 37edd21d2..97b9457fa 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ Commands | `:Commits` | Git commits (requires [fugitive.vim][f]) | | `:BCommits` | Git commits for the current buffer; visual-select lines to track changes in the range | | `:Commands` | Commands | -| `:Maps` | Normal mode mappings | +| `:Maps` | All mode mappings | | `:Helptags` | Help tags [1](#helptags) | | `:Filetypes` | File types @@ -299,6 +299,7 @@ Mappings | Mapping | Description | | --- | --- | +| `(fzf-maps)` | All mode mappings | | `(fzf-maps-n)` | Normal mode mappings | | `(fzf-maps-i)` | Insert mode mappings | | `(fzf-maps-x)` | Visual mode mappings | @@ -315,6 +316,12 @@ nmap (fzf-maps-n) xmap (fzf-maps-x) omap (fzf-maps-o) +" Or, to get all mapping from any mode +map (fzf-maps) +map! (fzf-maps) +tmap (fzf-maps) +lmap (fzf-maps) + " Insert mode completion imap (fzf-complete-word) imap (fzf-complete-path) diff --git a/autoload/fzf/vim.vim b/autoload/fzf/vim.vim index 7fd8314c0..146e1c0d5 100644 --- a/autoload/fzf/vim.vim +++ b/autoload/fzf/vim.vim @@ -1270,13 +1270,13 @@ 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, substitute(v, '^\*\?[@ ]\?', '', '')]) + let match = matchlist(elem, '^\(\w\)\?\s*\(\S*\)\s*\(.*\)$') + let [_, m, k, v] = match[0:3] + let maxlen = max([maxlen, len(m) + len(k)]) + call add(pairs, [m, k, substitute(v, '^\*\?[@ ]\?', '', '')]) endfor - let maxlen = min([maxlen, 35]) - return map(pairs, "printf('%-'.maxlen.'s', v:val[0]).' '.v:val[1]") + let maxlen = min([maxlen, 38]) + return map(pairs, "(v:val[0] != \"\"?v:val[0]:\" \").' '.printf('%-'.maxlen.'s', v:val[1]).' '.v:val[2]") endfunction function! s:highlight_keys(str) @@ -1293,15 +1293,24 @@ function! s:key_sink(line) \ substitute(key, '<[^ >]\+>', '\=eval("\"\\".submatch(0)."\"")', 'g')) endfunction -function! fzf#vim#maps(mode, ...) +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) ? '' : ('"'.v:register) let s:map_op = a:mode == 'o' ? v:operator : '' - redir => cout - silent execute 'verbose' a:mode.'map' - redir END + let l:cout = '' + if a:mode == '*' + for l:map in ['map', 'map!', 'tmap', 'lmap'] + redir =>> cout + silent execute 'verbose ' . l:map + redir END + endfor + else + redir => cout + silent execute 'verbose' a:mode.'map' + redir END + endif let list = [] let curr = '' for line in split(cout, "\n") @@ -1310,13 +1319,14 @@ function! fzf#vim#maps(mode, ...) call add(list, printf('%s %s', curr, s:green(src, 'Comment'))) let curr = '' else - if !empty(curr) + if !empty(curr) && curr !~ ".*No mapping.*" call add(list, curr) endif - let curr = line[3:] + " let curr = line[3:] + let curr = line endif endfor - if !empty(curr) + if !empty(curr) && curr !~ ".*No mapping.*" call add(list, curr) endif let aligned = s:align_pairs(list) diff --git a/doc/fzf-vim.txt b/doc/fzf-vim.txt index a04a17b69..85441ba46 100644 --- a/doc/fzf-vim.txt +++ b/doc/fzf-vim.txt @@ -136,7 +136,7 @@ COMMANDS *fzf-vim-commands* `:Commits` | Git commits (requires {fugitive.vim}{10}) `:BCommits` | Git commits for the current buffer; visual-select lines to track changes in the range `:Commands` | Commands - `:Maps` | Normal mode mappings + `:Maps` | All mode mappings `:Helptags` | Help tags [1] `:Filetypes` | File types ------------------+----------------------------------------------------------------------- @@ -369,6 +369,7 @@ MAPPINGS *fzf-vim-mappings* ---------------------------------+------------------------------------------ Mapping | Description ~ ---------------------------------+------------------------------------------ + (fzf-maps) | All mode mappings (fzf-maps-n) | Normal mode mappings (fzf-maps-i) | Insert mode mappings (fzf-maps-x) | Visual mode mappings @@ -385,6 +386,12 @@ MAPPINGS *fzf-vim-mappings* xmap (fzf-maps-x) omap (fzf-maps-o) + " Or, to get all mapping from any mode + map (fzf-maps) + map! (fzf-maps) + tmap (fzf-maps) + lmap (fzf-maps) + " Insert mode completion imap (fzf-complete-word) imap (fzf-complete-path) diff --git a/plugin/fzf.vim b/plugin/fzf.vim index ac0177bff..03d7f3c1b 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -64,7 +64,7 @@ call s:defs([ \'command! -bar -bang Windows call fzf#vim#windows(0)', \'command! -bar -bang -range=% Commits let b:fzf_winview = winsaveview() | ,call fzf#vim#commits(fzf#vim#with_preview({ "placeholder": "" }), 0)', \'command! -bar -bang -range=% BCommits let b:fzf_winview = winsaveview() | ,call fzf#vim#buffer_commits(fzf#vim#with_preview({ "placeholder": "" }), 0)', -\'command! -bar -bang Maps call fzf#vim#maps("n", 0)', +\'command! -bar -bang Maps call fzf#vim#maps("*", 0)', \'command! -bar -bang Filetypes call fzf#vim#filetypes(0)', \'command! -bang -nargs=* History call s:history(, fzf#vim#with_preview(), 0)'])