Add g:fzf_history_dir option

Close #176
This commit is contained in:
Junegunn Choi
2016-07-21 22:14:18 +09:00
parent 8b93c05d28
commit 491ff9942f
3 changed files with 43 additions and 24 deletions

View File

@@ -122,6 +122,12 @@ let g:fzf_colors =
\ 'marker': ['fg', 'Keyword'], \ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'], \ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] } \ 'header': ['fg', 'Comment'] }
" Enable per-command history.
" CTRL-N and CTRL-P will be automatically bound to next-history and
" previous-history instead of down and up. If you don't like the change,
" explicitly bind the keys to down and up in your $FZF_DEFAULT_OPTS.
let g:fzf_history_dir = '~/.fzf-history'
``` ```
#### Command-local options #### Command-local options

View File

@@ -100,11 +100,18 @@ function! s:defaults()
return empty(colors) ? '' : ('--color='.colors) return empty(colors) ? '' : ('--color='.colors)
endfunction endfunction
function! s:fzf(opts, extra) function! s:fzf(name, opts, extra)
let extra = empty(a:extra) ? fzf#vim#layout() : a:extra[0] let extra = empty(a:extra) ? fzf#vim#layout() : a:extra[0]
let eopts = has_key(extra, 'options') ? remove(extra, 'options') : '' let eopts = has_key(extra, 'options') ? remove(extra, 'options') : ''
let merged = extend(copy(a:opts), extra) let merged = extend(copy(a:opts), extra)
let merged.options = join(filter([s:defaults(), get(merged, 'options', ''), eopts], '!empty(v:val)')) let merged.options = join(filter([s:defaults(), get(merged, 'options', ''), eopts], '!empty(v:val)'))
if len(get(g:, 'fzf_history_dir', ''))
let dir = expand(g:fzf_history_dir)
if !isdirectory(dir)
call mkdir(dir, 'p')
endif
let merged.options = join(['--history', s:escape(dir.'/'.a:name), merged.options])
endif
return fzf#run(merged) return fzf#run(merged)
endfunction endfunction
@@ -203,7 +210,7 @@ function! fzf#vim#files(dir, ...)
let args.options .= ' --prompt '.shellescape(pathshorten(getcwd())).'/' let args.options .= ' --prompt '.shellescape(pathshorten(getcwd())).'/'
endif endif
return s:fzf(fzf#vim#wrap(args), a:000) return s:fzf('files', fzf#vim#wrap(args), a:000)
endfunction endfunction
" ------------------------------------------------------------------ " ------------------------------------------------------------------
@@ -268,7 +275,7 @@ function! fzf#vim#lines(...)
let nth = display_bufnames ? 3 : 2 let nth = display_bufnames ? 3 : 2
let [query, args] = (a:0 && type(a:1) == type('')) ? let [query, args] = (a:0 && type(a:1) == type('')) ?
\ [a:1, a:000[1:]] : ['', a:000] \ [a:1, a:000[1:]] : ['', a:000]
return s:fzf(fzf#vim#wrap({ return s:fzf('lines', fzf#vim#wrap({
\ 'source': lines, \ 'source': lines,
\ 'sink*': s:function('s:line_handler'), \ 'sink*': s:function('s:line_handler'),
\ 'options': '+m --tiebreak=index --prompt "Lines> " --ansi --extended --nth='.nth.'.. --reverse --tabstop=1'.s:q(query) \ 'options': '+m --tiebreak=index --prompt "Lines> " --ansi --extended --nth='.nth.'.. --reverse --tabstop=1'.s:q(query)
@@ -300,7 +307,7 @@ endfunction
function! fzf#vim#buffer_lines(...) function! fzf#vim#buffer_lines(...)
let [query, args] = (a:0 && type(a:1) == type('')) ? let [query, args] = (a:0 && type(a:1) == type('')) ?
\ [a:1, a:000[1:]] : ['', a:000] \ [a:1, a:000[1:]] : ['', a:000]
return s:fzf(fzf#vim#wrap({ return s:fzf('blines', fzf#vim#wrap({
\ 'source': s:buffer_lines(), \ 'source': s:buffer_lines(),
\ 'sink*': s:function('s:buffer_line_handler'), \ 'sink*': s:function('s:buffer_line_handler'),
\ 'options': '+m --tiebreak=index --prompt "BLines> " --ansi --extended --nth=2.. --reverse --tabstop=1'.s:q(query) \ 'options': '+m --tiebreak=index --prompt "BLines> " --ansi --extended --nth=2.. --reverse --tabstop=1'.s:q(query)
@@ -311,7 +318,7 @@ endfunction
" Colors " Colors
" ------------------------------------------------------------------ " ------------------------------------------------------------------
function! fzf#vim#colors(...) function! fzf#vim#colors(...)
return s:fzf({ return s:fzf('colors', {
\ 'source': map(split(globpath(&rtp, "colors/*.vim"), "\n"), \ 'source': map(split(globpath(&rtp, "colors/*.vim"), "\n"),
\ "substitute(fnamemodify(v:val, ':t'), '\\..\\{-}$', '', '')"), \ "substitute(fnamemodify(v:val, ':t'), '\\..\\{-}$', '', '')"),
\ 'sink': 'colo', \ 'sink': 'colo',
@@ -323,7 +330,7 @@ endfunction
" Locate " Locate
" ------------------------------------------------------------------ " ------------------------------------------------------------------
function! fzf#vim#locate(query, ...) function! fzf#vim#locate(query, ...)
return s:fzf(fzf#vim#wrap({ return s:fzf('locate', fzf#vim#wrap({
\ 'source': 'locate '.a:query, \ 'source': 'locate '.a:query,
\ 'options': '-m --prompt "Locate> "' \ 'options': '-m --prompt "Locate> "'
\}), a:000) \}), a:000)
@@ -371,7 +378,7 @@ function! s:cmd_history_sink(lines)
endfunction endfunction
function! fzf#vim#command_history(...) function! fzf#vim#command_history(...)
return s:fzf({ return s:fzf('history-command', {
\ 'source': s:history_source(':'), \ 'source': s:history_source(':'),
\ 'sink*': s:function('s:cmd_history_sink'), \ 'sink*': s:function('s:cmd_history_sink'),
\ 'options': '+m --ansi --prompt="Hist:> " --header-lines=1 --expect=ctrl-e --tiebreak=index'}, a:000) \ 'options': '+m --ansi --prompt="Hist:> " --header-lines=1 --expect=ctrl-e --tiebreak=index'}, a:000)
@@ -382,21 +389,21 @@ function! s:search_history_sink(lines)
endfunction endfunction
function! fzf#vim#search_history(...) function! fzf#vim#search_history(...)
return s:fzf({ return s:fzf('history-search', {
\ 'source': s:history_source('/'), \ 'source': s:history_source('/'),
\ 'sink*': s:function('s:search_history_sink'), \ 'sink*': s:function('s:search_history_sink'),
\ 'options': '+m --ansi --prompt="Hist/> " --header-lines=1 --expect=ctrl-e --tiebreak=index'}, a:000) \ 'options': '+m --ansi --prompt="Hist/> " --header-lines=1 --expect=ctrl-e --tiebreak=index'}, a:000)
endfunction endfunction
function! fzf#vim#history(...) function! fzf#vim#history(...)
return s:fzf(fzf#vim#wrap({ return s:fzf('history-files', fzf#vim#wrap({
\ 'source': reverse(s:all_files()), \ 'source': reverse(s:all_files()),
\ 'options': '-m --prompt "Hist> "' \ 'options': '-m --prompt "Hist> "'
\}), a:000) \}), a:000)
endfunction endfunction
" ------------------------------------------------------------------ " ------------------------------------------------------------------
" GitFiles[?] " GFiles[?]
" ------------------------------------------------------------------ " ------------------------------------------------------------------
function! s:git_status_sink(lines) abort function! s:git_status_sink(lines) abort
@@ -413,13 +420,13 @@ function! fzf#vim#gitfiles(args, ...)
return s:warn('Not in git repo') return s:warn('Not in git repo')
endif endif
if a:args != '?' if a:args != '?'
return s:fzf(fzf#vim#wrap({ return s:fzf('gfiles', fzf#vim#wrap({
\ 'source': 'git ls-files '.a:args, \ 'source': 'git ls-files '.a:args,
\ 'dir': root, \ 'dir': root,
\ 'options': '-m --prompt "GitFiles> "' \ 'options': '-m --prompt "GitFiles> "'
\}), a:000) \}), a:000)
endif endif
return s:fzf(fzf#vim#wrap({ return s:fzf('gfiles-diff', fzf#vim#wrap({
\ 'source': 'git -c color.status=always status --short', \ 'source': 'git -c color.status=always status --short',
\ 'dir': root, \ 'dir': root,
\ 'sink*': s:function('s:git_status_sink'), \ 'sink*': s:function('s:git_status_sink'),
@@ -488,7 +495,7 @@ endfunction
function! fzf#vim#buffers(...) function! fzf#vim#buffers(...)
let bufs = map(sort(s:buflisted(), 's:sort_buffers'), 's:format_buffer(v:val)') let bufs = map(sort(s:buflisted(), 's:sort_buffers'), 's:format_buffer(v:val)')
return s:fzf(fzf#vim#wrap({ return s:fzf('buffers', fzf#vim#wrap({
\ 'source': reverse(bufs), \ 'source': reverse(bufs),
\ 'sink*': s:function('s:bufopen'), \ 'sink*': s:function('s:bufopen'),
\ 'options': '+m -x --tiebreak=index --ansi -d "\t" -n 2,1..2 --prompt="Buf> "', \ 'options': '+m -x --tiebreak=index --ansi -d "\t" -n 2,1..2 --prompt="Buf> "',
@@ -538,7 +545,7 @@ endfunction
" ag command suffix, [options] " ag command suffix, [options]
function! fzf#vim#ag_raw(command_suffix, ...) function! fzf#vim#ag_raw(command_suffix, ...)
return s:fzf(fzf#vim#wrap({ return s:fzf('ag', fzf#vim#wrap({
\ 'source': 'ag --nogroup --column --color '.a:command_suffix, \ 'source': 'ag --nogroup --column --color '.a:command_suffix,
\ 'sink*': s:function('s:ag_handler'), \ 'sink*': s:function('s:ag_handler'),
\ 'options': '--ansi --delimiter : --nth 4..,.. --prompt "Ag> " '. \ 'options': '--ansi --delimiter : --nth 4..,.. --prompt "Ag> " '.
@@ -602,7 +609,7 @@ function! fzf#vim#buffer_tags(query, ...)
\ printf('ctags -f - --sort=no --excmd=number --language-force=%s %s', &filetype, expand('%:S')), \ printf('ctags -f - --sort=no --excmd=number --language-force=%s %s', &filetype, expand('%:S')),
\ printf('ctags -f - --sort=no --excmd=number %s', expand('%:S'))] \ printf('ctags -f - --sort=no --excmd=number %s', expand('%:S'))]
try try
return s:fzf(fzf#vim#wrap({ return s:fzf('btags', fzf#vim#wrap({
\ 'source': s:btags_source(tag_cmds), \ 'source': s:btags_source(tag_cmds),
\ 'sink*': s:function('s:btags_sink'), \ 'sink*': s:function('s:btags_sink'),
\ 'options': '--reverse -m -d "\t" --with-nth 1,4.. -n 1 --prompt "BTags> "'.s:q(a:query)}), args) \ 'options': '--reverse -m -d "\t" --with-nth 1,4.. -n 1 --prompt "BTags> "'.s:q(a:query)}), args)
@@ -668,7 +675,7 @@ function! fzf#vim#tags(query, ...)
let proc = 'perl -ne ''unless (/^\!/) { s/^(.*?)\t(.*?)\t/'.s:yellow('\1', 'Function').'\t'.s:blue('\2', 'String').'\t/; print }'' ' let proc = 'perl -ne ''unless (/^\!/) { s/^(.*?)\t(.*?)\t/'.s:yellow('\1', 'Function').'\t'.s:blue('\2', 'String').'\t/; print }'' '
let copt = '--ansi ' let copt = '--ansi '
endif endif
return s:fzf(fzf#vim#wrap({ return s:fzf('tags', fzf#vim#wrap({
\ 'source': proc.shellescape(fnamemodify(tagfile, ':t')), \ 'source': proc.shellescape(fnamemodify(tagfile, ':t')),
\ 'sink*': s:function('s:tags_sink'), \ 'sink*': s:function('s:tags_sink'),
\ 'dir': fnamemodify(tagfile, ':h'), \ 'dir': fnamemodify(tagfile, ':h'),
@@ -693,7 +700,7 @@ function! fzf#vim#snippets(...)
endif endif
let aligned = sort(s:align_lists(items(list))) let aligned = sort(s:align_lists(items(list)))
let colored = map(aligned, 's:yellow(v:val[0])."\t".v:val[1]') let colored = map(aligned, 's:yellow(v:val[0])."\t".v:val[1]')
return s:fzf({ return s:fzf('snippets', {
\ 'source': colored, \ 'source': colored,
\ 'options': '--ansi --tiebreak=index +m -n 1 -d "\t"', \ 'options': '--ansi --tiebreak=index +m -n 1 -d "\t"',
\ 'sink': s:function('s:inject_snippet')}, a:000) \ 'sink': s:function('s:inject_snippet')}, a:000)
@@ -757,7 +764,7 @@ function! fzf#vim#commands(...)
silent command silent command
redir END redir END
let list = split(cout, "\n") let list = split(cout, "\n")
return s:fzf({ return s:fzf('commands', {
\ 'source': extend(extend(list[0:0], map(list[1:], 's:format_cmd(v:val)')), s:excmds()), \ 'source': extend(extend(list[0:0], map(list[1:], 's:format_cmd(v:val)')), s:excmds()),
\ 'sink*': s:function('s:command_sink'), \ 'sink*': s:function('s:command_sink'),
\ 'options': '--ansi --expect '.get(g:, 'fzf_commands_expect', 'ctrl-x'). \ 'options': '--ansi --expect '.get(g:, 'fzf_commands_expect', 'ctrl-x').
@@ -787,7 +794,7 @@ function! fzf#vim#marks(...)
silent marks silent marks
redir END redir END
let list = split(cout, "\n") let list = split(cout, "\n")
return s:fzf(fzf#vim#wrap({ return s:fzf('marks', fzf#vim#wrap({
\ 'source': extend(list[0:0], map(list[1:], 's:format_mark(v:val)')), \ 'source': extend(list[0:0], map(list[1:], 's:format_mark(v:val)')),
\ 'sink*': s:function('s:mark_sink'), \ 'sink*': s:function('s:mark_sink'),
\ 'options': '+m -x --ansi --tiebreak=index --header-lines 1 --tiebreak=begin --prompt "Marks> "'}), a:000) \ 'options': '+m -x --ansi --tiebreak=index --header-lines 1 --tiebreak=begin --prompt "Marks> "'}), a:000)
@@ -808,7 +815,7 @@ endfunction
function! fzf#vim#helptags(...) function! fzf#vim#helptags(...)
let tags = uniq(sort(split(globpath(&runtimepath, '**/doc/tags'), '\n'))) let tags = uniq(sort(split(globpath(&runtimepath, '**/doc/tags'), '\n')))
return s:fzf({ return s:fzf('helptags', {
\ 'source': "grep -H '.*' ".join(map(tags, 'shellescape(v:val)')). \ 'source': "grep -H '.*' ".join(map(tags, 'shellescape(v:val)')).
\ "| perl -ne '/(.*?):(.*?)\t(.*?)\t/; printf(qq(".s:green('%-40s', 'Label')."\t%s\t%s\n), $2, $3, $1)' | sort", \ "| perl -ne '/(.*?):(.*?)\t(.*?)\t/; printf(qq(".s:green('%-40s', 'Label')."\t%s\t%s\n), $2, $3, $1)' | sort",
\ 'sink': s:function('s:helptag_sink'), \ 'sink': s:function('s:helptag_sink'),
@@ -819,7 +826,7 @@ endfunction
" File types " File types
" ------------------------------------------------------------------ " ------------------------------------------------------------------
function! fzf#vim#filetypes(...) function! fzf#vim#filetypes(...)
return s:fzf({ return s:fzf('filetypes', {
\ 'source': sort(map(split(globpath(&rtp, 'syntax/*.vim'), '\n'), \ 'source': sort(map(split(globpath(&rtp, 'syntax/*.vim'), '\n'),
\ 'fnamemodify(v:val, ":t:r")')), \ 'fnamemodify(v:val, ":t:r")')),
\ 'sink': 'setf', \ 'sink': 'setf',
@@ -855,7 +862,7 @@ function! fzf#vim#windows(...)
\ s:format_win(t, w, buffers[w-1]))) \ s:format_win(t, w, buffers[w-1])))
endfor endfor
endfor endfor
return s:fzf({ return s:fzf('windows', {
\ 'source': extend(['Tab Win Name'], lines), \ 'source': extend(['Tab Win Name'], lines),
\ 'sink': s:function('s:windows_sink'), \ 'sink': s:function('s:windows_sink'),
\ 'options': '+m --ansi --tiebreak=begin --header-lines=1'}, a:000) \ 'options': '+m --ansi --tiebreak=begin --header-lines=1'}, a:000)
@@ -923,7 +930,7 @@ function! s:commits(buffer_local, args)
let options.options .= ' --header ":: Press '.s:magenta('CTRL-S', 'Special').' to toggle sort"' let options.options .= ' --header ":: Press '.s:magenta('CTRL-S', 'Special').' to toggle sort"'
endif endif
return s:fzf(options, a:args) return s:fzf(a:buffer_local ? 'bcommits' : 'commits', options, a:args)
endfunction endfunction
function! fzf#vim#commits(...) function! fzf#vim#commits(...)
@@ -992,7 +999,7 @@ function! fzf#vim#maps(mode, ...)
let sorted = sort(aligned) let sorted = sort(aligned)
let colored = map(sorted, 's:highlight_keys(v:val)') let colored = map(sorted, 's:highlight_keys(v:val)')
let pcolor = a:mode == 'x' ? 9 : a:mode == 'o' ? 10 : 12 let pcolor = a:mode == 'x' ? 9 : a:mode == 'o' ? 10 : 12
return s:fzf({ return s:fzf('maps', {
\ 'source': colored, \ 'source': colored,
\ 'sink': s:function('s:key_sink'), \ 'sink': s:function('s:key_sink'),
\ 'options': '--prompt "Maps ('.a:mode.')> " --ansi --no-hscroll --nth 1,.. --color prompt:'.pcolor}, a:000) \ 'options': '--prompt "Maps ('.a:mode.')> " --ansi --no-hscroll --nth 1,.. --color prompt:'.pcolor}, a:000)

View File

@@ -149,6 +149,12 @@ Global options~
\ 'marker': ['fg', 'Keyword'], \ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'], \ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] } \ 'header': ['fg', 'Comment'] }
" Enable per-command history.
" CTRL-N and CTRL-P will be automatically bound to next-history and
" previous-history instead of down and up. If you don't like the change,
" explicitly bind the keys to down and up in your $FZF_DEFAULT_OPTS.
let g:fzf_history_dir = '~/.fzf-history'
< <
Command-local options~ Command-local options~