From ec0d685fafd8e4b3bf0907faac4fa3314a85062d Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 22 Aug 2015 22:57:28 +0900 Subject: [PATCH] Add Marks command --- README.md | 1 + plugin/fzf.vim | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/README.md b/README.md index 457e701..4bd6e03 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ Commands | `Colors` | Color schemes | | `Ag [PATTERN]` | [ag][ag] search result (`CTRL-A` to select all, `CTRL-D` to deselect all) | | `Lines` | Lines in loaded buffers | +| `Marks` | Marks | | `Tags` | Tags in the project (`ctags -R`) | | `BTags` | Tags in the current buffer | | `Locate PATTERN` | `locate` command output | diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 3149e31..1d6a9c2 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -400,6 +400,37 @@ endfunction command! -bang Commands call s:commands(0) +" ------------------------------------------------------------------ +" Marks +" ------------------------------------------------------------------ +function! s:format_mark(line) + return substitute(a:line, '\S', '\=s:yellow(submatch(0), 1)', '') +endfunction + +function! s:mark_sink(lines) + if len(a:lines) < 2 + return + endif + let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], '') + if !empty(cmd) + execute 'silent' cmd + endif + execute 'normal! `'.matchstr(a:lines[1], '\S').'zz' +endfunction + +function! s:marks(bang) + redir => cout + silent marks + redir END + let list = split(cout, "\n") + call s:fzf({ + \ 'source': extend(list[0:0], map(list[1:], 's:format_mark(v:val)')), + \ 'sink*': function('s:mark_sink'), + \ 'options': '+m --ansi --header-lines 1 --tiebreak=begin --prompt "Marks> "'.s:expect()}, a:bang) +endfunction + +command! -bang Marks call s:marks(0) + " ---------------------------------------------------------------------------- " Completion helper " ----------------------------------------------------------------------------