1 Commits

Author SHA1 Message Date
Junegunn Choi
db71151970 Add g:fzf_grep_preview_window for enabling Ag/grep preview
Close #225
2016-11-14 02:44:14 +09:00
9 changed files with 238 additions and 571 deletions

View File

@@ -5,7 +5,7 @@
- [ ] Suggestion
- OS
- [ ] Linux
- [ ] macOS
- [ ] Mac OS X
- [ ] Windows
- [ ] Etc.
- Vim
@@ -23,7 +23,7 @@ Before submitting
Start Vim with a minimal configuration
======================================
vim -Nu <(curl https://gist.githubusercontent.com/junegunn/6936bf79fedd3a079aeb1dd2f3c81ef5/raw)
vim -Nu <(curl https://gist.githubusercontent.com/junegunn/6936bf79fedd3a079aeb1dd2f3c81ef5/raw/vimrc)
-->

View File

@@ -29,23 +29,12 @@ selector with fzf.
fzf is an independent command-line program and thus requires an external
terminal emulator when on GVim. You may or may not like the experience. Also
note that Windows support is experimental at the moment.
note that fzf currently does not compile on Windows.
Installation
------------
Use [vim-plug](https://github.com/junegunn/vim-plug) or any Vim plugin
manager of your choice.
If you already installed fzf using [Homebrew](https://brew.sh/), the following
should suffice:
```vim
Plug '/usr/local/opt/fzf'
Plug 'junegunn/fzf.vim'
```
But if you want to install fzf as well using vim-plug:
Using [vim-plug](https://github.com/junegunn/vim-plug):
```vim
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
@@ -54,6 +43,8 @@ Plug 'junegunn/fzf.vim'
- `dir` and `do` options are not mandatory
- Use `./install --bin` instead if you don't need fzf outside of Vim
- If you installed fzf using Homebrew, the following should suffice:
- `Plug '/usr/local/opt/fzf' | Plug 'junegunn/fzf.vim'`
- Make sure to use Vim 7.4 or above
Commands
@@ -102,10 +93,6 @@ pathogen#helptags()`. [↩](#a1))
#### Global options
See [README-VIM.md][readme-vim] of the main fzf repository for details.
[readme-vim]: https://github.com/junegunn/fzf/blob/master/README-VIM.md#configuration
```vim
" This is the default extra key bindings
let g:fzf_action = {
@@ -120,7 +107,6 @@ let g:fzf_layout = { 'down': '~40%' }
" In Neovim, you can set up fzf window using a Vim command
let g:fzf_layout = { 'window': 'enew' }
let g:fzf_layout = { 'window': '-tabnew' }
let g:fzf_layout = { 'window': '10split enew' }
" Customize fzf colors to match your color scheme
let g:fzf_colors =
@@ -131,7 +117,6 @@ let g:fzf_colors =
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
@@ -148,6 +133,12 @@ let g:fzf_history_dir = '~/.local/share/fzf-history'
#### Command-local options
```vim
" [Files] Extra options for fzf
" e.g. File preview using Highlight
" (http://www.andre-simon.de/doku/highlight/en/highlight.html)
let g:fzf_files_options =
\ '--preview "(highlight -O ansi {} || cat {}) 2> /dev/null | head -'.&lines.'"'
" [Buffers] Jump to the existing window if possible
let g:fzf_buffers_jump = 1
@@ -159,49 +150,25 @@ let g:fzf_tags_command = 'ctags -R'
" [Commands] --expect expression for directly executing the command
let g:fzf_commands_expect = 'alt-enter,ctrl-x'
" [Ag / fzf#vim#grep] Command to preview the content
" - Requires Ruby
" - Install Highlight or CodeRay for syntax highlighting
let g:fzf_grep_preview_window = 'right:50%'
```
#### Advanced customization
#### Advanced customization using autoload functions
You can use autoload functions to define your own commands.
```vim
" Command for git grep
" - fzf#vim#grep(command, with_column, [options], [fullscreen])
" git grep
command! -bang -nargs=* GGrep
\ call fzf#vim#grep('git grep --line-number '.shellescape(<q-args>), 0, <bang>0)
" Override Colors command. You can safely do this in your .vimrc as fzf.vim
" will not override existing commands.
command! -bang Colors
\ call fzf#vim#colors({'left': '15%', 'options': '--reverse --margin 30%,0'}, <bang>0)
" Augmenting Ag command using fzf#vim#with_preview function
" * fzf#vim#with_preview([[options], preview window, [toggle keys...]])
" * For syntax-highlighting, Ruby and any of the following tools are required:
" - Highlight: http://www.andre-simon.de/doku/highlight/en/highlight.php
" - CodeRay: http://coderay.rubychan.de/
" - Rouge: https://github.com/jneen/rouge
"
" :Ag - Start fzf with hidden preview window that can be enabled with "?" key
" :Ag! - Start fzf in fullscreen and display the preview window above
command! -bang -nargs=* Ag
\ call fzf#vim#ag(<q-args>,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
" Similarly, we can apply it to fzf#vim#grep. To use ripgrep instead of ag:
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always '.shellescape(<q-args>), 1,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
" Likewise, Files command with preview window
command! -bang -nargs=? -complete=dir Files
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)
" We use VimEnter event so that the code is run after fzf.vim is loaded
autocmd VimEnter * command! Colors
\ call fzf#vim#colors({'left': '15%', 'options': '--reverse --margin 30%,0'})
```
Mappings
@@ -260,7 +227,7 @@ following exceptions:
- Or a function to extract completion prefix
- Both `source` and `options` can be given as funcrefs that take the
completion prefix as the argument and return the final value
- `sink` or `sink*` are ignored
- `sink` or `sink*` are not allowed
#### Reducer example

View File

@@ -1,4 +1,4 @@
" Copyright (c) 2017 Junegunn Choi
" Copyright (c) 2016 Junegunn Choi
"
" MIT License
"
@@ -28,83 +28,11 @@ set cpo&vim
" Common
" ------------------------------------------------------------------
let s:is_win = has('win32') || has('win64')
let s:layout_keys = ['window', 'up', 'down', 'left', 'right']
let s:bin_dir = expand('<sfile>:h:h:h').'/bin/'
let s:bin = {
\ 'preview': s:bin_dir.(executable('ruby') ? 'preview.rb' : 'preview.sh'),
\ 'tags': s:bin_dir.'tags.pl' }
let s:TYPE = {'dict': type({}), 'funcref': type(function('call')), 'string': type(''), 'list': type([])}
if s:is_win
if has('nvim')
let s:bin.preview = split(system('for %A in ("'.s:bin.preview.'") do echo %~sA'), "\n")[1]
else
let s:bin.preview = fnamemodify(s:bin.preview, ':8')
endif
let s:bin.preview = (executable('ruby') ? 'ruby' : 'bash').' '.escape(s:bin.preview, '\')
endif
let s:bin = { 'preview': expand('<sfile>:h:h:h').'/bin/preview.rb' }
let s:TYPE = {'dict': type({}), 'funcref': type(function('call')), 'string': type('')}
function! s:extend_opts(dict, eopts, prepend)
if empty(a:eopts)
return
endif
if has_key(a:dict, 'options')
if type(a:dict.options) == s:TYPE.list && type(a:eopts) == s:TYPE.list
if a:prepend
let a:dict.options = extend(copy(a:eopts), a:dict.options)
else
call extend(a:dict.options, a:eopts)
endif
else
let all_opts = a:prepend ? [a:eopts, a:dict.options] : [a:dict.options, a:eopts]
let a:dict.options = join(map(all_opts, 'type(v:val) == s:TYPE.list ? join(map(copy(v:val), "fzf#shellescape(v:val)")) : v:val'))
endif
else
let a:dict.options = a:eopts
endif
endfunction
function! s:merge_opts(dict, eopts)
return s:extend_opts(a:dict, a:eopts, 0)
endfunction
function! s:prepend_opts(dict, eopts)
return s:extend_opts(a:dict, a:eopts, 1)
endfunction
" [[options to wrap], preview window expression, [toggle-preview keys...]]
function! fzf#vim#with_preview(...)
" Default options
let options = {}
let window = 'right'
let args = copy(a:000)
" Options to wrap
if len(args) && type(args[0]) == s:TYPE.dict
let options = copy(args[0])
call remove(args, 0)
endif
" Preview window
if len(args) && type(args[0]) == s:TYPE.string
if args[0] !~# '^\(up\|down\|left\|right\)'
throw 'invalid preview window: '.args[0]
endif
let window = args[0]
call remove(args, 0)
endif
let preview = ['--preview-window', window, '--preview', s:bin.preview.' '.(window =~ 'up\|down' ? '-v' : '').' {}']
if len(args)
call extend(preview, ['--bind', join(map(args, 'v:val.":toggle-preview"'), ',')])
endif
call s:merge_opts(options, preview)
return options
endfunction
function! s:remove_layout(opts)
function s:remove_layout(opts)
for key in s:layout_keys
if has_key(a:opts, key)
call remove(a:opts, key)
@@ -118,14 +46,15 @@ function! fzf#vim#wrap(opts)
return fzf#wrap(a:opts)
endfunction
" Deprecated
function! fzf#vim#layout(...)
return (a:0 && a:1) ? {} : copy(get(g:, 'fzf_layout', g:fzf#vim#default_layout))
endfunction
function! s:wrap(name, opts, bang)
" fzf#wrap does not append --expect if sink or sink* is found
let opts = copy(a:opts)
let options = ''
if has_key(opts, 'options')
let options = type(opts.options) == s:TYPE.list ? join(opts.options) : opts.options
endif
if options !~ '--expect' && has_key(opts, 'sink*')
if get(opts, 'options', '') !~ '--expect' && has_key(opts, 'sink*')
let Sink = remove(opts, 'sink*')
let wrapped = fzf#wrap(a:name, opts, a:bang)
let wrapped['sink*'] = Sink
@@ -147,6 +76,10 @@ function! s:escape(path)
return escape(a:path, ' $%#''"\')
endfunction
function! s:q1(str)
return "'".substitute(a:str, "'", "'\\\\''", 'g')."'"
endfunction
if v:version >= 704
function! s:function(name)
return function(a:name)
@@ -159,12 +92,9 @@ else
endif
function! s:get_color(attr, ...)
let gui = has('termguicolors') && &termguicolors
let fam = gui ? 'gui' : 'cterm'
let pat = gui ? '^#[a-f0-9]\+' : '^[0-9]\+$'
for group in a:000
let code = synIDattr(synIDtrans(hlID(group)), a:attr, fam)
if code =~? pat
let code = synIDattr(synIDtrans(hlID(group)), a:attr, 'cterm')
if code =~ '^[0-9]\+$'
return code
endif
endfor
@@ -173,19 +103,11 @@ endfunction
let s:ansi = {'black': 30, 'red': 31, 'green': 32, 'yellow': 33, 'blue': 34, 'magenta': 35, 'cyan': 36}
function! s:csi(color, fg)
let prefix = a:fg ? '38;' : '48;'
if a:color[0] == '#'
return prefix.'2;'.join(map([a:color[1:2], a:color[3:4], a:color[5:6]], 'str2nr(v:val, 16)'), ';')
endif
return prefix.'5;'.a:color
endfunction
function! s:ansi(str, group, default, ...)
let fg = s:get_color('fg', a:group)
let bg = s:get_color('bg', a:group)
let color = s:csi(empty(fg) ? s:ansi[a:default] : fg, 1) .
\ (empty(bg) ? '' : s:csi(bg, 0))
let color = (empty(fg) ? s:ansi[a:default] : ('38;5;'.fg)) .
\ (empty(bg) ? '' : (';48;5;'.bg))
return printf("\x1b[%s%sm%s\x1b[m", color, a:0 ? ';1' : '', a:str)
endfunction
@@ -196,7 +118,13 @@ for s:color_name in keys(s:ansi)
endfor
function! s:buflisted()
return filter(range(1, bufnr('$')), 'buflisted(v:val) && getbufvar(v:val, "&filetype") != "qf"')
return filter(range(1, bufnr('$')), 'buflisted(v:val)')
endfunction
function! s:defaults()
let rules = copy(get(g:, 'fzf_colors', {}))
let colors = join(map(items(filter(map(rules, 'call("s:get_color", v:val)'), '!empty(v:val)')), 'join(v:val, ":")'), ',')
return empty(colors) ? '' : ('--color='.colors)
endfunction
function! s:fzf(name, opts, extra)
@@ -216,7 +144,7 @@ function! s:fzf(name, opts, extra)
let eopts = has_key(extra, 'options') ? remove(extra, 'options') : ''
let merged = extend(copy(a:opts), extra)
call s:merge_opts(merged, eopts)
let merged.options = join(filter([s:defaults(), get(merged, 'options', ''), eopts], '!empty(v:val)'))
return fzf#run(s:wrap(a:name, merged, bang))
endfunction
@@ -225,12 +153,6 @@ let s:default_action = {
\ 'ctrl-x': 'split',
\ 'ctrl-v': 'vsplit' }
function! s:action_for(key, ...)
let default = a:0 ? a:1 : ''
let Cmd = get(get(g:, 'fzf_action', s:default_action), a:key, default)
return type(Cmd) == s:TYPE.string ? Cmd : default
endfunction
function! s:open(cmd, target)
if stridx('edit', a:cmd) == 0 && fnamemodify(a:target, ':p') ==# expand('%:p')
return
@@ -260,7 +182,7 @@ function! s:warn(message)
return 0
endfunction
function! fzf#vim#_uniq(list)
function! s:uniq(list)
let visited = {}
let ret = []
for l in a:list
@@ -275,30 +197,19 @@ endfunction
" ------------------------------------------------------------------
" Files
" ------------------------------------------------------------------
function! s:shortpath()
let short = fnamemodify(getcwd(), ':~:.')
if !has('win32unix')
let short = pathshorten(short)
endif
let slash = (s:is_win && !&shellslash) ? '\' : '/'
return empty(short) ? '~'.slash : short . (short =~ escape(slash, '\').'$' ? '' : slash)
endfunction
function! fzf#vim#files(dir, ...)
let args = {}
let args = {'options': '-m '.get(g:, 'fzf_files_options', '')}
if !empty(a:dir)
if !isdirectory(expand(a:dir))
return s:warn('Invalid directory')
endif
let slash = (s:is_win && !&shellslash) ? '\\' : '/'
let dir = substitute(a:dir, '[/\\]*$', slash, '')
let dir = substitute(a:dir, '/*$', '/', '')
let args.dir = dir
let args.options .= ' --prompt '.shellescape(dir)
else
let dir = s:shortpath()
let args.options .= ' --prompt '.shellescape(pathshorten(getcwd())).'/'
endif
let args.options = ['-m', '--prompt', strwidth(dir) < &columns / 2 - 20 ? dir : '> ']
call s:merge_opts(args, get(g:, 'fzf_files_options', []))
return s:fzf('files', args, a:000)
endfunction
@@ -310,7 +221,7 @@ function! s:line_handler(lines)
return
endif
normal! m'
let cmd = s:action_for(a:lines[0])
let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], '')
if !empty(cmd) && stridx('edit', cmd) < 0
execute 'silent' cmd
endif
@@ -379,7 +290,7 @@ function! s:buffer_line_handler(lines)
return
endif
normal! m'
let cmd = s:action_for(a:lines[0])
let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], '')
if !empty(cmd)
execute 'silent' cmd
endif
@@ -407,12 +318,9 @@ endfunction
" Colors
" ------------------------------------------------------------------
function! fzf#vim#colors(...)
let colors = split(globpath(&rtp, "colors/*.vim"), "\n")
if has('packages')
let colors += split(globpath(&packpath, "pack/*/opt/*/colors/*.vim"), "\n")
endif
return s:fzf('colors', {
\ 'source': fzf#vim#_uniq(map(colors, "substitute(fnamemodify(v:val, ':t'), '\\..\\{-}$', '', '')")),
\ 'source': map(split(globpath(&rtp, "colors/*.vim"), "\n"),
\ "substitute(fnamemodify(v:val, ':t'), '\\..\\{-}$', '', '')"),
\ 'sink': 'colo',
\ 'options': '+m --prompt="Colors> "'
\}, a:000)
@@ -432,11 +340,9 @@ endfunction
" History[:/]
" ------------------------------------------------------------------
function! s:all_files()
return fzf#vim#_uniq(map(
\ filter([expand('%')], 'len(v:val)')
\ + filter(map(s:buflisted_sorted(), 'bufname(v:val)'), 'len(v:val)')
\ + filter(copy(v:oldfiles), "filereadable(expand(v:val))"),
\ 'fnamemodify(v:val, ":~:.")'))
return extend(
\ filter(reverse(copy(v:oldfiles)), "filereadable(expand(v:val))"),
\ filter(map(s:buflisted(), 'bufname(v:val)'), '!empty(v:val)'))
endfunction
function! s:history_source(type)
@@ -490,8 +396,8 @@ endfunction
function! fzf#vim#history(...)
return s:fzf('history-files', {
\ 'source': s:all_files(),
\ 'options': ['-m', '--header-lines', !empty(expand('%')), '--prompt', 'Hist> ']
\ 'source': reverse(s:all_files()),
\ 'options': '-m --prompt "Hist> "'
\}, a:000)
endfunction
@@ -499,7 +405,14 @@ endfunction
" GFiles[?]
" ------------------------------------------------------------------
" helper function to get the git root. Uses vim-fugitive if available for EXTRA SPEED!
function! s:get_git_root()
if exists('*fugitive#repo')
try
return fugitive#repo().tree()
catch
endtry
endif
let root = split(system('git rev-parse --show-toplevel'), '\n')[0]
return v:shell_error ? '' : root
endfunction
@@ -511,7 +424,7 @@ function! fzf#vim#gitfiles(args, ...)
endif
if a:args != '?'
return s:fzf('gfiles', {
\ 'source': 'git ls-files '.a:args.(s:is_win ? '' : ' | uniq'),
\ 'source': 'git ls-files '.a:args,
\ 'dir': root,
\ 'options': '-m --prompt "GitFiles> "'
\}, a:000)
@@ -523,7 +436,7 @@ function! fzf#vim#gitfiles(args, ...)
let wrapped = fzf#wrap({
\ 'source': 'git -c color.status=always status --short --untracked-files=all',
\ 'dir': root,
\ 'options': ['--ansi', '--multi', '--nth', '2..,..', '--tiebreak=index', '--prompt', 'GitFiles?> ', '--preview', 'sh -c "(git diff --color=always -- {-1} | sed 1,4d; cat {-1}) | head -500"']
\ 'options': '--ansi --multi --nth 2..,.. --prompt "GitFiles?> " --preview ''sh -c "(git diff --color=always -- {-1} | sed 1,4d; cat {-1}) | head -500"'''
\})
call s:remove_layout(wrapped)
let wrapped.common_sink = remove(wrapped, 'sink*')
@@ -570,7 +483,7 @@ function! s:bufopen(lines)
return
endif
endif
let cmd = s:action_for(a:lines[0])
let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], '')
if !empty(cmd)
execute 'silent' cmd
endif
@@ -591,21 +504,16 @@ endfunction
function! s:sort_buffers(...)
let [b1, b2] = map(copy(a:000), 'get(g:fzf#vim#buffers, v:val, v:val)')
" Using minus between a float and a number in a sort function causes an error
return b1 < b2 ? 1 : -1
endfunction
function! s:buflisted_sorted()
return sort(s:buflisted(), 's:sort_buffers')
return b1 > b2 ? 1 : -1
endfunction
function! fzf#vim#buffers(...)
let [query, args] = (a:0 && type(a:1) == type('')) ?
\ [a:1, a:000[1:]] : ['', a:000]
let bufs = map(sort(s:buflisted(), 's:sort_buffers'), 's:format_buffer(v:val)')
return s:fzf('buffers', {
\ 'source': map(s:buflisted_sorted(), 's:format_buffer(v:val)'),
\ 'source': reverse(bufs),
\ 'sink*': s:function('s:bufopen'),
\ 'options': '+m -x --tiebreak=index --header-lines=1 --ansi -d "\t" -n 2,1..2 --prompt="Buf> "'.s:q(query)
\}, args)
\ 'options': '+m -x --tiebreak=index --header-lines=1 --ansi -d "\t" -n 2,1..2 --prompt="Buf> "',
\}, a:000)
endfunction
" ------------------------------------------------------------------
@@ -626,7 +534,7 @@ function! s:ag_handler(lines, with_column)
return
endif
let cmd = s:action_for(a:lines[0], 'e')
let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], 'e')
let list = map(filter(a:lines[1:], 'len(v:val)'), 's:ag_to_qf(v:val, a:with_column)')
if empty(list)
return
@@ -658,15 +566,12 @@ function! fzf#vim#ag(query, ...)
let query = empty(a:query) ? '^(?=.)' : a:query
let args = copy(a:000)
let ag_opts = len(args) > 1 && type(args[0]) == s:TYPE.string ? remove(args, 0) : ''
let command = ag_opts . ' ' . fzf#shellescape(query)
let command = ag_opts . ' ' . s:q1(query)
return call('fzf#vim#ag_raw', insert(args, command, 0))
endfunction
" ag command suffix, [options]
function! fzf#vim#ag_raw(command_suffix, ...)
if !executable('ag')
return s:warn('ag is not found')
endif
return call('fzf#vim#grep', extend(['ag --nogroup --column --color '.a:command_suffix, 1], a:000))
endfunction
@@ -682,12 +587,19 @@ function! fzf#vim#grep(grep_command, with_column, ...)
let words = empty(words) ? ['grep'] : words
let name = join(words, '-')
let capname = join(map(words, 'toupper(v:val[0]).v:val[1:]'), '')
let textcol = a:with_column ? '4..' : '3..'
let preview = ''
if executable('ruby') && exists('g:fzf_grep_preview_window')
let preview = printf(' --preview-window %s --preview "%s"\ {1}\ {2}\ %d',
\ g:fzf_grep_preview_window,
\ shellescape(s:bin.preview), g:fzf_grep_preview_window =~ 'up\|down')
endif
let opts = {
\ 'source': a:grep_command,
\ 'column': a:with_column,
\ 'options': ['--ansi', '--prompt', capname.'> ',
\ '--multi', '--bind', 'alt-a:select-all,alt-d:deselect-all',
\ '--color', 'hl:68,hl+:110']
\ 'options': '--ansi --delimiter : --nth '.textcol.',.. --prompt "'.capname.'> " '.
\ '--multi --bind alt-a:select-all,alt-d:deselect-all '.
\ '--color hl:68,hl+:110'.preview
\}
function! opts.sink(lines)
return s:ag_handler(a:lines, self.column)
@@ -706,7 +618,7 @@ function! s:btags_source(tag_cmds)
for cmd in a:tag_cmds
let lines = split(system(cmd), "\n")
if !v:shell_error && len(lines)
if !v:shell_error
break
endif
endfor
@@ -723,7 +635,7 @@ function! s:btags_sink(lines)
return
endif
normal! m'
let cmd = s:action_for(a:lines[0])
let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], '')
if !empty(cmd)
execute 'silent' cmd '%'
endif
@@ -742,20 +654,15 @@ function! s:btags_sink(lines)
endfunction
function! s:q(query)
return ' --query '.fzf#shellescape(a:query)
return ' --query '.s:q1(a:query)
endfunction
" query, [[tag commands], options]
function! fzf#vim#buffer_tags(query, ...)
let args = copy(a:000)
let escaped = fzf#shellescape(expand('%'))
let null = s:is_win ? 'nul' : '/dev/null'
let tag_cmds = (len(args) > 1 && type(args[0]) != type({})) ? remove(args, 0) : [
\ printf('ctags -f - --sort=no --excmd=number --language-force=%s %s 2> %s', &filetype, escaped, null),
\ printf('ctags -f - --sort=no --excmd=number %s 2> %s', escaped, null)]
if type(tag_cmds) != type([])
let tag_cmds = [tag_cmds]
endif
let tag_cmds = len(args) > 1 ? remove(args, 0) : [
\ printf('ctags -f - --sort=no --excmd=number --language-force=%s %s', &filetype, expand('%:S')),
\ printf('ctags -f - --sort=no --excmd=number %s', expand('%:S'))]
try
return s:fzf('btags', {
\ 'source': s:btags_source(tag_cmds),
@@ -775,17 +682,14 @@ function! s:tags_sink(lines)
endif
normal! m'
let qfl = []
let cmd = s:action_for(a:lines[0], 'e')
let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], 'e')
try
let [magic, &magic, wrapscan, &wrapscan, acd, &acd] = [&magic, 0, &wrapscan, 1, &acd, 0]
let [magic, &magic, wrapscan, &wrapscan] = [&magic, 0, &wrapscan, 1]
for line in a:lines[1:]
try
let parts = split(line, '\t\zs')
let excmd = matchstr(join(parts[2:-2], '')[:-2], '^.*\ze;"\t')
let base = fnamemodify(parts[-1], ':h')
let relpath = parts[1][:-2]
let abspath = relpath =~ (s:is_win ? '^[A-Z]:\' : '^/') ? relpath : join([base, relpath], '/')
call s:open(cmd, expand(abspath, 1))
let parts = split(line, '\t\zs')
let excmd = matchstr(join(parts[2:], ''), '^.*\ze;"\t')
call s:open(cmd, parts[1][:-2])
execute excmd
call add(qfl, {'filename': expand('%'), 'lnum': line('.'), 'text': getline('.')})
catch /^Vim:Interrupt$/
@@ -795,7 +699,7 @@ function! s:tags_sink(lines)
endtry
endfor
finally
let [&magic, &wrapscan, &acd] = [magic, wrapscan, acd]
let [&magic, &wrapscan] = [magic, wrapscan]
endtry
if len(qfl) > 1
call setqflist(qfl)
@@ -807,9 +711,6 @@ function! s:tags_sink(lines)
endfunction
function! fzf#vim#tags(query, ...)
if !executable('perl')
return s:warn('Tags command requires perl')
endif
if empty(tagfiles())
call inputsave()
echohl WarningMsg
@@ -817,9 +718,9 @@ function! fzf#vim#tags(query, ...)
echohl None
call inputrestore()
redraw
if gen =~? '^y'
if gen =~ '^y'
call s:warn('Preparing tags')
call system(get(g:, 'fzf_tags_command', 'ctags -R'.(s:is_win ? ' --output-format=e-ctags' : '')))
call system(get(g:, 'fzf_tags_command', 'ctags -R'))
if empty(tagfiles())
return s:warn('Failed to create tags')
endif
@@ -828,20 +729,21 @@ function! fzf#vim#tags(query, ...)
endif
endif
let tagfiles = tagfiles()
let v2_limit = 1024 * 1024 * 200
for tagfile in tagfiles
let v2_limit -= getfsize(tagfile)
if v2_limit < 0
break
endif
endfor
let opts = v2_limit < 0 ? '--algo=v1 ' : ''
let tagfile = tagfiles()[0]
" We don't want to apply --ansi option when tags file is large as it makes
" processing much slower.
if getfsize(tagfile) > 1024 * 1024 * 20
let proc = 'grep -v ''^\!'' '
let copt = ''
else
let proc = 'perl -ne ''unless (/^\!/) { s/^(.*?)\t(.*?)\t/'.s:yellow('\1', 'Function').'\t'.s:blue('\2', 'String').'\t/; print }'' '
let copt = '--ansi '
endif
return s:fzf('tags', {
\ 'source': fzf#shellescape(s:bin.tags).' '.join(map(tagfiles, 'fzf#shellescape(fnamemodify(v:val, ":p"))')),
\ 'source': proc.shellescape(fnamemodify(tagfile, ':t')),
\ 'sink*': s:function('s:tags_sink'),
\ 'options': opts.'--nth 1..2 -m --tiebreak=begin --prompt "Tags> "'.s:q(a:query)}, a:000)
\ 'dir': fnamemodify(tagfile, ':h'),
\ 'options': copt.'-m --tiebreak=begin --prompt "Tags> "'.s:q(a:query)}, a:000)
endfunction
" ------------------------------------------------------------------
@@ -944,7 +846,7 @@ function! s:mark_sink(lines)
if len(a:lines) < 2
return
endif
let cmd = s:action_for(a:lines[0])
let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], '')
if !empty(cmd)
execute 'silent' cmd
endif
@@ -975,22 +877,14 @@ function! s:helptag_sink(line)
endfunction
function! fzf#vim#helptags(...)
if !executable('grep') || !executable('perl')
return s:warn('Helptags command requires grep and perl')
endif
let sorted = sort(split(globpath(&runtimepath, 'doc/tags'), '\n'))
let tags = exists('*uniq') ? uniq(sorted) : fzf#vim#_uniq(sorted)
let sorted = sort(split(globpath(&runtimepath, '**/doc/tags'), '\n'))
let tags = exists('*uniq') ? uniq(sorted) : s:uniq(sorted)
if exists('s:helptags_script')
silent! call delete(s:helptags_script)
endif
let s:helptags_script = tempname()
call writefile(['/('.(s:is_win ? '^[A-Z]:\/.*?[^:]' : '.*?').'):(.*?)\t(.*?)\t/; printf(qq('.s:green('%-40s', 'Label').'\t%s\t%s\n), $2, $3, $1)'], s:helptags_script)
return s:fzf('helptags', {
\ 'source': 'grep -H ".*" '.join(map(tags, 'fzf#shellescape(v:val)')).
\ ' | perl -n '.fzf#shellescape(s:helptags_script).' | sort',
\ '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",
\ 'sink': s:function('s:helptag_sink'),
\ 'options': ['--ansi', '+m', '--tiebreak=begin', '--with-nth', '..-2']}, a:000)
\ 'options': '--ansi +m --tiebreak=begin --with-nth ..-2'}, a:000)
endfunction
" ------------------------------------------------------------------
@@ -1047,13 +941,12 @@ function! s:commits_sink(lines)
return
endif
let diff = a:lines[0] == 'ctrl-d'
let cmd = s:action_for(a:lines[0], 'e')
let cmd = get(extend({'ctrl-d': ''}, get(g:, 'fzf_action', s:default_action)), a:lines[0], 'e')
let buf = bufnr('')
for idx in range(1, len(a:lines) - 1)
let sha = matchstr(a:lines[idx], '[0-9a-f]\{7,9}')
let sha = matchstr(a:lines[idx], '[0-9a-f]\{7}')
if !empty(sha)
if diff
if empty(cmd)
if idx > 1
execute 'tab sb' buf
endif
@@ -1073,11 +966,11 @@ function! s:commits(buffer_local, args)
return s:warn('Not in git repository')
endif
let source = 'git log '.get(g:, 'fzf_commits_log_options', '--color=always '.fzf#shellescape('--format=%C(auto)%h%d %s %C(green)%cr'))
let current = expand('%')
let source = 'git log '.get(g:, 'fzf_commits_log_options', '--graph --color=always --format="%C(auto)%h%d %s %C(green)%cr"')
let current = expand('%:S')
let managed = 0
if !empty(current)
call system('git show '.fzf#shellescape(current).' 2> '.(s:is_win ? 'nul' : '/dev/null'))
call system('git show '.current.' 2> /dev/null')
let managed = !v:shell_error
endif
@@ -1085,9 +978,7 @@ function! s:commits(buffer_local, args)
if !managed
return s:warn('The current buffer is not in the working tree')
endif
let source .= ' --follow '.fzf#shellescape(current)
else
let source .= ' --graph'
let source .= ' --follow '.current
endif
let command = a:buffer_local ? 'BCommits' : 'Commits'
@@ -1095,20 +986,15 @@ function! s:commits(buffer_local, args)
let options = {
\ 'source': source,
\ 'sink*': s:function('s:commits_sink'),
\ 'options': ['--ansi', '--multi', '--tiebreak=index', '--reverse',
\ '--inline-info', '--prompt', command.'> ', '--bind=ctrl-s:toggle-sort',
\ '--header', ':: Press '.s:magenta('CTRL-S', 'Special').' to toggle sort',
\ '--expect='.expect_keys]
\ 'options': '--ansi --multi --no-sort --tiebreak=index --reverse '.
\ '--inline-info --prompt "'.command.'> " --bind=ctrl-s:toggle-sort '.
\ '--expect='.expect_keys
\ }
if a:buffer_local
let options.options[-2] .= ', '.s:magenta('CTRL-D', 'Special').' to diff'
let options.options[-1] .= ',ctrl-d'
endif
if !s:is_win
call extend(options.options,
\ ['--preview', 'grep -o "[a-f0-9]\{7,\}" <<< {} | xargs git show --format=format: --color=always | head -200'])
let options.options .= ',ctrl-d --header ":: Press '.s:magenta('CTRL-S', 'Special').' to toggle sort, '.s:magenta('CTRL-D', 'Special').' to diff"'
else
let options.options .= ' --header ":: Press '.s:magenta('CTRL-S', 'Special').' to toggle sort"'
endif
return s:fzf(a:buffer_local ? 'bcommits' : 'commits', options, a:args)
@@ -1164,12 +1050,13 @@ function! fzf#vim#maps(mode, ...)
let list = []
let curr = ''
for line in split(cout, "\n")
if line =~ "^\t"
let src = ' '.join(reverse(reverse(split(split(line)[-1], '/'))[0:2]), '/')
let src = matchstr(line, 'Last set from \zs.*')
if empty(src)
let curr = line[3:]
else
let src = ' '.join(reverse(reverse(split(src, '/'))[0:2]), '/')
call add(list, printf('%s %s', curr, s:green(src, 'Comment')))
let curr = ''
else
let curr = line[3:]
endif
endfor
if !empty(curr)
@@ -1196,7 +1083,7 @@ endfunction
function! s:complete_trigger()
let opts = copy(s:opts)
call s:prepend_opts(opts, ['+m', '-q', s:query])
let opts.options = printf('+m -q %s %s', shellescape(s:query), get(opts, 'options', ''))
let opts['sink*'] = s:function('s:complete_insert')
let s:reducer = s:pluck(opts, 'reducer', s:function('s:first_line'))
call fzf#run(opts)
@@ -1241,20 +1128,16 @@ endfunction
function! fzf#vim#complete(...)
if a:0 == 0
let s:opts = fzf#wrap()
let s:opts = g:fzf#vim#default_layout
elseif type(a:1) == s:TYPE.dict
let s:opts = copy(a:1)
elseif type(a:1) == s:TYPE.string
let s:opts = extend({'source': a:1}, get(a:000, 1, fzf#wrap()))
else
echoerr 'Invalid argument: '.string(a:000)
return ''
endif
for s in ['sink', 'sink*']
if has_key(s:opts, s)
call remove(s:opts, s)
if has_key(a:1, 'sink') || has_key(a:1, 'sink*')
echoerr 'sink not allowed'
return ''
endif
endfor
let s:opts = copy(a:1)
else
let s:opts = extend({'source': a:1}, g:fzf#vim#default_layout)
endif
let eol = col('$')
let ve = &ve
@@ -1277,14 +1160,8 @@ function! fzf#vim#complete(...)
let s:opts = s:eval(s:opts, 'options', s:query)
let s:opts = s:eval(s:opts, 'extra_options', s:query)
if has_key(s:opts, 'extra_options')
call s:merge_opts(s:opts, remove(s:opts, 'extra_options'))
endif
if has_key(s:opts, 'options')
if type(s:opts.options) == s:TYPE.list
call add(s:opts.options, '--no-expect')
else
let s:opts.options .= ' --no-expect'
endif
let s:opts.options =
\ join(filter([get(s:opts, 'options', ''), remove(s:opts, 'extra_options')], '!empty(v:val)'))
endif
call feedkeys("\<Plug>(-fzf-complete-trigger)")

View File

@@ -23,7 +23,6 @@
let s:cpo_save = &cpo
set cpo&vim
let s:is_win = has('win32') || has('win64')
function! s:extend(base, extra)
let base = copy(a:base)
@@ -49,7 +48,7 @@ endif
function! fzf#vim#complete#word(...)
return fzf#vim#complete(s:extend({
\ 'source': 'cat /usr/share/dict/words'},
\ get(a:000, 0, fzf#wrap())))
\ get(a:000, 0, g:fzf#vim#default_layout)))
endfunction
" ----------------------------------------------------------------------------
@@ -59,26 +58,25 @@ endfunction
" ----------------------------------------------------------------------------
function! s:file_split_prefix(prefix)
let expanded = expand(a:prefix)
let slash = (s:is_win && !&shellslash) ? '\\' : '/'
return isdirectory(expanded) ?
\ [expanded,
\ substitute(a:prefix, '[/\\]*$', slash, ''),
\ substitute(a:prefix, '/*$', '/', ''),
\ ''] :
\ [fnamemodify(expanded, ':h'),
\ substitute(fnamemodify(a:prefix, ':h'), '[/\\]*$', slash, ''),
\ substitute(fnamemodify(a:prefix, ':h'), '/*$', '/', ''),
\ fnamemodify(expanded, ':t')]
endfunction
function! s:file_source(prefix)
let [dir, head, tail] = s:file_split_prefix(a:prefix)
return printf(
\ "cd %s && ".s:file_cmd." | sed %s",
\ fzf#shellescape(dir), fzf#shellescape('s:^:'.(empty(a:prefix) || a:prefix == tail ? '' : head).':'))
\ "cd %s && ".s:file_cmd." | sed 's:^:%s:'",
\ shellescape(dir), empty(a:prefix) || a:prefix == tail ? '' : head)
endfunction
function! s:file_options(prefix)
let [_, head, tail] = s:file_split_prefix(a:prefix)
return ['--prompt', head, '--query', tail]
return printf('--prompt %s --query %s', shellescape(head), shellescape(tail))
endfunction
function! s:fname_prefix(str)
@@ -130,7 +128,7 @@ function! fzf#vim#complete#path(command, ...)
return fzf#vim#complete(s:extend({
\ 'prefix': s:function('s:fname_prefix'),
\ 'source': s:function('s:file_source'),
\ 'options': s:function('s:file_options')}, get(a:000, 0, fzf#wrap())))
\ 'options': s:function('s:file_options')}, get(a:000, 0, g:fzf#vim#default_layout)))
endfunction
" ----------------------------------------------------------------------------
@@ -149,13 +147,13 @@ function! fzf#vim#complete#line(...)
\ 'prefix': '^.*$',
\ 'source': lines,
\ 'options': '--tiebreak=index --ansi --nth '.nth.'.. --tabstop=1',
\ 'reducer': s:function('s:reduce_line')}, get(a:000, 0, fzf#wrap())))
\ 'reducer': s:function('s:reduce_line')}, get(a:000, 0, g:fzf#vim#default_layout)))
endfunction
function! fzf#vim#complete#buffer_line(...)
return fzf#vim#complete(s:extend({
call fzf#vim#complete(s:extend({
\ 'prefix': '^.*$',
\ 'source': fzf#vim#_uniq(getline(1, '$'))}, get(a:000, 0, fzf#wrap())))
\ 'source': s:uniq(getline(1, '$'))}, get(a:000, 0, g:fzf#vim#default_layout)))
endfunction
let &cpo = s:cpo_save

View File

@@ -1,52 +1,21 @@
#!/usr/bin/env ruby
#
# usage: ./preview.rb [-v] FILENAME[:LINE][:IGNORED]
# usage: ./preview.rb FILENAME LINENO VSPLIT(0|1)
require 'shellwords'
COMMAND = %[(highlight -O ansi -l {} || coderay {} || rougify {} || cat {}) 2> /dev/null]
COMMAND = %[(highlight -O ansi -l {} || coderay {} || cat {}) 2> /dev/null]
ANSI = /\x1b\[[0-9;]*m/
REVERSE = "\x1b[7m"
RESET = "\x1b[m"
split = ARGV.delete('-v')
def usage
puts "usage: #$0 [-v] FILENAME[:LINENO][:IGNORED]"
exit 1
end
usage if ARGV.empty?
file, center, extra = ARGV.first.split(':')
if ARGV.first =~ /^[A-Z]:\\/
file << ':' + center
center = extra
end
usage unless file
path = File.expand_path(file)
unless File.readable? path
puts "File not found: #{file}"
exit 1
end
if `file --mime "#{file}"` =~ /binary/
puts "#{file} is a binary file"
exit 0
end
center = (center || 0).to_i
if ENV['FZF_PREVIEW_HEIGHT']
height = ENV['FZF_PREVIEW_HEIGHT'].to_i
else
height = File.readable?('/dev/tty') ? `stty size < /dev/tty`.split.first.to_i : 40
height /= 2 if split
height -= 2 # preview border
end
file, center, split = ARGV.fetch(0), ARGV.fetch(1).to_i, ARGV.fetch(2) == '1'
height = File.readable?('/dev/tty') ? `stty size < /dev/tty`.split.first.to_i : 40
height /= 2 if split
height -= 2 # preview border
offset = [1, center - height / 3].max
IO.popen(['sh', '-c', COMMAND.gsub('{}', Shellwords.shellescape(path))]) do |io|
IO.popen(['sh', '-c', COMMAND.gsub('{}', Shellwords.shellescape(file))]) do |io|
io.each_line.drop(offset - 1).take(height).each_with_index do |line, lno|
if lno + offset == center
puts REVERSE + line.chomp.gsub(ANSI) { |m| m + REVERSE } + RESET

View File

@@ -1,57 +0,0 @@
#!/bin/bash
REVERSE="\x1b[7m"
RESET="\x1b[m"
if [ "$1" == "-v" ]; then
SPLIT=1
shift
fi
if [ -z "$1" ]; then
echo "usage: $0 [-v] FILENAME[:LINENO][:IGNORED]"
exit 1
fi
IFS=':' read -r -a INPUT <<< "$1"
FILE=${INPUT[0]}
CENTER=${INPUT[1]}
if [[ $1 =~ ^[A-Z]:\\ ]]; then
FILE=$FILE:${INPUT[1]}
CENTER=${INPUT[2]}
fi
if [ ! -r "$FILE" ]; then
echo "File not found ${FILE}"
exit 1
fi
if [[ "$(file --mime "$FILE")" =~ binary ]]; then
echo "$1 is a binary file"
exit 0
fi
if [ -z "$CENTER" ]; then
CENTER=1
fi
if [ -n "$FZF_PREVIEW_HEIGHT" ]; then
LINES=$FZF_PREVIEW_HEIGHT
else
if [ -r /dev/tty ]; then
LINES=$(stty size < /dev/tty | awk '{print $1}')
else
LINES=40
fi
if [ -n "$SPLIT" ]; then
LINES=$(($LINES/2)) # using horizontal split
fi
LINES=$(($LINES-2)) # remove preview border
fi
FIRST=$(($CENTER-$LINES/3))
FIRST=$(($FIRST < 1 ? 1 : $FIRST))
LAST=$((${FIRST}+${LINES}-1))
awk "NR >= $FIRST && NR <= $LAST {if (NR == $CENTER) printf(\"$REVERSE%5d %s\n$RESET\", NR, \$0); else printf(\"%5d %s\n\", NR, \$0)}" $FILE

View File

@@ -1,15 +0,0 @@
#!/usr/bin/env perl
use strict;
foreach my $file (@ARGV) {
open my $lines, $file;
while (<$lines>) {
unless (/^\!/) {
s/^[^\t]*/sprintf("%-24s", $&)/e;
s/$/\t$file/;
print;
}
}
close $lines;
}

View File

@@ -1,4 +1,4 @@
fzf-vim.txt fzf-vim Last change: October 21 2017
fzf-vim.txt fzf-vim Last change: September 20 2015
FZF-VIM - TABLE OF CONTENTS *fzf-vim* *fzf-vim-toc*
==============================================================================
@@ -8,14 +8,10 @@ FZF-VIM - TABLE OF CONTENTS *fzf-vim* *fzf-vim-to
Installation
Commands
Customization
Global options
Command-local options
Advanced customization
Mappings
Usage
Completion helper
Reducer example
Status line (neovim)
License
FZF :HEART: VIM *fzf-vim-fzf-heart-vim*
@@ -57,48 +53,35 @@ selector with fzf.
fzf is an independent command-line program and thus requires an external
terminal emulator when on GVim. You may or may not like the experience. Also
note that Windows support is experimental at the moment.
note that fzf currently does not compile on Windows.
INSTALLATION *fzf-vim-installation*
==============================================================================
Use {vim-plug}{4} or any Vim plugin manager of your choice.
If you already installed fzf using {Homebrew}{5}, the following should
suffice:
Using {vim-plug}{4}:
>
Plug '/usr/local/opt/fzf'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': 'yes \| ./install' }
Plug 'junegunn/fzf.vim'
<
But if you want to install fzf as well using vim-plug:
>
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
<
- `dir` and `do` options are not mandatory
- Use `./install--bin` instead if you don't need fzf outside of Vim
- Make sure to use Vim 7.4 or above
{4} https://github.com/junegunn/vim-plug
{5} https://brew.sh/
COMMANDS *fzf-vim-commands*
==============================================================================
-----------------+-----------------------------------------------------------------------
Command | List ~
-----------------+-----------------------------------------------------------------------
-----------------+-------------------------------------------------------------------
Command | List ~
-----------------+-------------------------------------------------------------------
`Files[PATH]` | Files (similar to `:FZF` )
`GFiles[OPTS]` | Git files ( `gitls-files` )
`GFiles?` | Git files ( `gitstatus` )
`GFiles [OPTS]` | Git files (git ls-files)
`GFiles?` | Git files (git status)
`Buffers` | Open buffers
`Colors` | Color schemes
`Ag[PATTERN]` | {ag}{6} search result ( `ALT-A` to select all, `ALT-D` to deselect all)
`Lines[QUERY]` | Lines in loaded buffers
`BLines[QUERY]` | Lines in the current buffer
`Ag[PATTERN]` | {ag}{5} search result (ALT-A to select all, ALT-D to deselect all)
`Lines [QUERY]` | Lines in loaded buffers
`BLines [QUERY]` | Lines in the current buffer
`Tags[QUERY]` | Tags in the project ( `ctags-R` )
`BTags[QUERY]` | Tags in the current buffer
`Marks` | Marks
@@ -107,40 +90,36 @@ COMMANDS *fzf-vim-commands*
`History` | `v:oldfiles` and open buffers
`History:` | Command history
`History/` | Search history
`Snippets` | Snippets ({UltiSnips}{7})
`Commits` | Git commits (requires {fugitive.vim}{8})
`Snippets` | Snippets ({UltiSnips}{6})
`Commits` | Git commits (requires {fugitive.vim}{7})
`BCommits` | Git commits for the current buffer
`Commands` | Commands
`Maps` | Normal mode mappings
`Helptags` | Help tags [1]
`Filetypes` | File types
-----------------+-----------------------------------------------------------------------
*g:fzf_command_prefix*
-----------------+-------------------------------------------------------------------
- Most commands support CTRL-T / CTRL-X / CTRL-V key bindings to open in a new
tab, a new split, or in a new vertical split
- Bang-versions of the commands (e.g. `Ag!`) will open fzf in fullscreen
- You can set `g:fzf_command_prefix` to give the same prefix to the commands
- e.g. `letg:fzf_command_prefix='Fzf'` and you have `FzfFiles`, etc.
- e.g. `let g:fzf_command_prefix = 'Fzf'` and you have `FzfFiles`, etc.
(1: `Helptags` will shadow the command of the same name from {pathogen}{9}.
(1: `Helptags` will shadow the command of the same name from {pathogen}{8}.
But its functionality is still available via `call pathogen#helptags()`.)
{6} https://github.com/ggreer/the_silver_searcher
{7} https://github.com/SirVer/ultisnips
{8} https://github.com/tpope/vim-fugitive
{9} https://github.com/tpope/vim-pathogen
{5} https://github.com/ggreer/the_silver_searcher
{6} https://github.com/SirVer/ultisnips
{7} https://github.com/tpope/vim-fugitive
{8} https://github.com/tpope/vim-pathogen
< Customization >_____________________________________________________________~
*fzf-vim-customization*
*g:fzf_action* *g:fzf_layout* *g:fzf_colors* *g:fzf_commits_log_options*
Global options~
*fzf-vim-global-options*
See {README-VIM.md}{10} of the main fzf repository for details.
>
" This is the default extra key bindings
let g:fzf_action = {
@@ -155,7 +134,6 @@ See {README-VIM.md}{10} of the main fzf repository for details.
" In Neovim, you can set up fzf window using a Vim command
let g:fzf_layout = { 'window': 'enew' }
let g:fzf_layout = { 'window': '-tabnew' }
let g:fzf_layout = { 'window': '10split enew' }
" Customize fzf colors to match your color scheme
let g:fzf_colors =
@@ -166,7 +144,6 @@ See {README-VIM.md}{10} of the main fzf repository for details.
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
@@ -179,20 +156,21 @@ See {README-VIM.md}{10} of the main fzf repository for details.
" explicitly bind the keys to down and up in your $FZF_DEFAULT_OPTS.
let g:fzf_history_dir = '~/.local/share/fzf-history'
<
{10} https://github.com/junegunn/fzf/blob/master/README-VIM.md#configuration
Command-local options~
*fzf-vim-command-local-options*
*g:fzf_buffers_jump* *g:fzf_commits_log_options* *g:fzf_tags_command*
*g:fzf_commands_expect*
>
" [Files] Extra options for fzf
" e.g. File preview using coderay (http://coderay.rubychan.de/)
let g:fzf_files_options =
\ '--preview "(coderay {} || cat {}) 2> /dev/null | head -'.&lines.'"'
" [Buffers] Jump to the existing window if possible
let g:fzf_buffers_jump = 1
" [[B]Commits] Customize the options used by 'git log':
let g:fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'
let g:fzf_commits_log_options = \
'--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'
" [Tags] Command to generate tags file
let g:fzf_tags_command = 'ctags -R'
@@ -201,49 +179,20 @@ Command-local options~
let g:fzf_commands_expect = 'alt-enter,ctrl-x'
<
Advanced customization~
*fzf-vim-advanced-customization*
Advanced customization using autoload functions~
You can use autoload functions to define your own commands.
>
" Command for git grep
" - fzf#vim#grep(command, with_column, [options], [fullscreen])
" git grep
command! -bang -nargs=* GGrep
\ call fzf#vim#grep('git grep --line-number '.shellescape(<q-args>), 0, <bang>0)
" Override Colors command. You can safely do this in your .vimrc as fzf.vim
" will not override existing commands.
command! -bang Colors
\ call fzf#vim#colors({'left': '15%', 'options': '--reverse --margin 30%,0'}, <bang>0)
" Augmenting Ag command using fzf#vim#with_preview function
" * fzf#vim#with_preview([[options], preview window, [toggle keys...]])
" * For syntax-highlighting, Ruby and any of the following tools are required:
" - Highlight: http://www.andre-simon.de/doku/highlight/en/highlight.php
" - CodeRay: http://coderay.rubychan.de/
" - Rouge: https://github.com/jneen/rouge
"
" :Ag - Start fzf with hidden preview window that can be enabled with "?" key
" :Ag! - Start fzf in fullscreen and display the preview window above
command! -bang -nargs=* Ag
\ call fzf#vim#ag(<q-args>,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
" Similarly, we can apply it to fzf#vim#grep. To use ripgrep instead of ag:
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always '.shellescape(<q-args>), 1,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
" Likewise, Files command with preview window
command! -bang -nargs=? -complete=dir Files
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)
" We use VimEnter event so that the code is run after fzf.vim is loaded
autocmd VimEnter * command! Colors
\ call fzf#vim#colors({'left': '15%', 'options': '--reverse --margin 30%,0'})
<
MAPPINGS *fzf-vim-mappings*
==============================================================================
@@ -302,7 +251,7 @@ following exceptions:
- Or a function to extract completion prefix
- Both `source` and `options` can be given as funcrefs that take the completion
prefix as the argument and return the final value
- `sink` or `sink*` are ignored
- `sink` or `sink*` are not allowed
Reducer example~
@@ -319,20 +268,6 @@ Reducer example~
\ 'left': 20})
<
STATUS LINE (NEOVIM) *fzf-vim-status-lineneovim*
==============================================================================
>
function! s:fzf_statusline()
" Override statusline as you like
highlight fzf1 ctermfg=161 ctermbg=251
highlight fzf2 ctermfg=23 ctermbg=251
highlight fzf3 ctermfg=237 ctermbg=251
setlocal statusline=%#fzf1#\ >\ %#fzf2#fz%#fzf3#f
endfunction
autocmd! User FzfStatusLine call <SID>fzf_statusline()
<
LICENSE *fzf-vim-license*
==============================================================================

View File

@@ -23,7 +23,8 @@
let s:cpo_save = &cpo
set cpo&vim
let s:is_win = has('win32') || has('win64')
let g:fzf#vim#default_layout = {'down': '~40%'}
function! s:defs(commands)
let prefix = get(g:, 'fzf_command_prefix', '')
@@ -32,35 +33,32 @@ function! s:defs(commands)
return
endif
for command in a:commands
let name = ':'.prefix.matchstr(command, '\C[A-Z]\S\+')
if 2 != exists(name)
execute substitute(command, '\ze\C[A-Z]', prefix, '')
endif
execute substitute(command, '\ze\C[A-Z]', prefix, '')
endfor
endfunction
call s:defs([
\'command! -bang -nargs=? -complete=dir Files call fzf#vim#files(<q-args>, <bang>0)',
\'command! -bang -nargs=? GitFiles call fzf#vim#gitfiles(<q-args>, <bang>0)',
\'command! -bang -nargs=? GFiles call fzf#vim#gitfiles(<q-args>, <bang>0)',
\'command! -bar -bang -nargs=? -complete=buffer Buffers call fzf#vim#buffers(<q-args>, <bang>0)',
\'command! -bang -nargs=* Lines call fzf#vim#lines(<q-args>, <bang>0)',
\'command! -bang -nargs=* BLines call fzf#vim#buffer_lines(<q-args>, <bang>0)',
\'command! -bar -bang Colors call fzf#vim#colors(<bang>0)',
\'command! -bang -nargs=+ -complete=dir Locate call fzf#vim#locate(<q-args>, <bang>0)',
\'command! -bang -nargs=* Ag call fzf#vim#ag(<q-args>, <bang>0)',
\'command! -bang -nargs=* Tags call fzf#vim#tags(<q-args>, <bang>0)',
\'command! -bang -nargs=* BTags call fzf#vim#buffer_tags(<q-args>, <bang>0)',
\'command! -bar -bang Snippets call fzf#vim#snippets(<bang>0)',
\'command! -bar -bang Commands call fzf#vim#commands(<bang>0)',
\'command! -bar -bang Marks call fzf#vim#marks(<bang>0)',
\'command! -bar -bang Helptags call fzf#vim#helptags(<bang>0)',
\'command! -bar -bang Windows call fzf#vim#windows(<bang>0)',
\'command! -bar -bang Commits call fzf#vim#commits(<bang>0)',
\'command! -bar -bang BCommits call fzf#vim#buffer_commits(<bang>0)',
\'command! -bar -bang Maps call fzf#vim#maps("n", <bang>0)',
\'command! -bar -bang Filetypes call fzf#vim#filetypes(<bang>0)',
\'command! -bang -nargs=* History call s:history(<q-args>, <bang>0)'])
\'command! -bang -nargs=? -complete=dir Files call fzf#vim#files(<q-args>, <bang>0)',
\'command! -bang -nargs=? GitFiles call fzf#vim#gitfiles(<q-args>, <bang>0)',
\'command! -bang -nargs=? GFiles call fzf#vim#gitfiles(<q-args>, <bang>0)',
\'command! -bang Buffers call fzf#vim#buffers(<bang>0)',
\'command! -bang -nargs=* Lines call fzf#vim#lines(<q-args>, <bang>0)',
\'command! -bang -nargs=* BLines call fzf#vim#buffer_lines(<q-args>, <bang>0)',
\'command! -bang Colors call fzf#vim#colors(<bang>0)',
\'command! -bang -nargs=+ -complete=dir Locate call fzf#vim#locate(<q-args>, <bang>0)',
\'command! -bang -nargs=* Ag call fzf#vim#ag(<q-args>, <bang>0)',
\'command! -bang -nargs=* Tags call fzf#vim#tags(<q-args>, <bang>0)',
\'command! -bang -nargs=* BTags call fzf#vim#buffer_tags(<q-args>, <bang>0)',
\'command! -bang Snippets call fzf#vim#snippets(<bang>0)',
\'command! -bang Commands call fzf#vim#commands(<bang>0)',
\'command! -bang Marks call fzf#vim#marks(<bang>0)',
\'command! -bang Helptags call fzf#vim#helptags(<bang>0)',
\'command! -bang Windows call fzf#vim#windows(<bang>0)',
\'command! -bang Commits call fzf#vim#commits(<bang>0)',
\'command! -bang BCommits call fzf#vim#buffer_commits(<bang>0)',
\'command! -bang Maps call fzf#vim#maps("n", <bang>0)',
\'command! -bang Filetypes call fzf#vim#filetypes(<bang>0)',
\'command! -bang -nargs=* History call s:history(<q-args>, <bang>0)'])
function! s:history(arg, bang)
let bang = a:bang || a:arg[len(a:arg)-1] == '!'
@@ -83,13 +81,13 @@ if has('nvim') && get(g:, 'fzf_nvim_statusline', 1)
doautocmd User FzfStatusLine
else
if $TERM !~ "256color"
highlight default fzf1 ctermfg=1 ctermbg=8 guifg=#E12672 guibg=#565656
highlight default fzf2 ctermfg=2 ctermbg=8 guifg=#BCDDBD guibg=#565656
highlight default fzf3 ctermfg=7 ctermbg=8 guifg=#D9D9D9 guibg=#565656
highlight fzf1 ctermfg=1 ctermbg=8 guifg=#E12672 guibg=#565656
highlight fzf2 ctermfg=2 ctermbg=8 guifg=#BCDDBD guibg=#565656
highlight fzf3 ctermfg=7 ctermbg=8 guifg=#D9D9D9 guibg=#565656
else
highlight default fzf1 ctermfg=161 ctermbg=238 guifg=#E12672 guibg=#565656
highlight default fzf2 ctermfg=151 ctermbg=238 guifg=#BCDDBD guibg=#565656
highlight default fzf3 ctermfg=252 ctermbg=238 guifg=#D9D9D9 guibg=#565656
highlight fzf1 ctermfg=161 ctermbg=238 guifg=#E12672 guibg=#565656
highlight fzf2 ctermfg=151 ctermbg=238 guifg=#BCDDBD guibg=#565656
highlight fzf3 ctermfg=252 ctermbg=238 guifg=#D9D9D9 guibg=#565656
endif
setlocal statusline=%#fzf1#\ >\ %#fzf2#fz%#fzf3#f
endif
@@ -124,14 +122,9 @@ augroup fzf_buffers
augroup END
inoremap <expr> <plug>(fzf-complete-word) fzf#vim#complete#word()
if s:is_win
inoremap <expr> <plug>(fzf-complete-path) fzf#vim#complete#path('dir /s/b')
inoremap <expr> <plug>(fzf-complete-file) fzf#vim#complete#path('dir /s/b/a:-d')
else
inoremap <expr> <plug>(fzf-complete-path) fzf#vim#complete#path("find . -path '*/\.*' -prune -o -print \| sed '1d;s:^..::'")
inoremap <expr> <plug>(fzf-complete-file) fzf#vim#complete#path("find . -path '*/\.*' -prune -o -type f -print -o -type l -print \| sed 's:^..::'")
endif
inoremap <expr> <plug>(fzf-complete-file-ag) fzf#vim#complete#path('ag -l -g ""')
inoremap <expr> <plug>(fzf-complete-path) fzf#vim#complete#path("find . -path '*/\.*' -prune -o -print \| sed '1d;s:^..::'")
inoremap <expr> <plug>(fzf-complete-file) fzf#vim#complete#path("find . -path '*/\.*' -prune -o -type f -print -o -type l -print \| sed 's:^..::'")
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()