mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-07 05:04:30 +08:00
Compare commits
83 Commits
grep-previ
...
revert-500
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
529894d769 | ||
|
|
004af25150 | ||
|
|
4b9e2a03fe | ||
|
|
5c6cee878a | ||
|
|
f31a2925fe | ||
|
|
b51382fe9e | ||
|
|
fbfbd04870 | ||
|
|
852b38db2a | ||
|
|
6ac8d1f742 | ||
|
|
121bd70fcf | ||
|
|
b24038960e | ||
|
|
36f6e6b5b0 | ||
|
|
2fd046fa76 | ||
|
|
e7928d154a | ||
|
|
df79877245 | ||
|
|
0b0d9f0912 | ||
|
|
39f0c2d0a4 | ||
|
|
34ceec14d2 | ||
|
|
b73cec55f0 | ||
|
|
25ea6371b2 | ||
|
|
4e603e4fab | ||
|
|
13b27c45c8 | ||
|
|
e246016844 | ||
|
|
a4d4986d18 | ||
|
|
b0baf7593d | ||
|
|
dda682ad69 | ||
|
|
71cc4c5037 | ||
|
|
057853a248 | ||
|
|
3334d62749 | ||
|
|
469ac6bfce | ||
|
|
fa91d53f5c | ||
|
|
1e40de4f2d | ||
|
|
61bcdb146f | ||
|
|
d62ec0b113 | ||
|
|
914355df94 | ||
|
|
7e868c49ac | ||
|
|
43a570d6e6 | ||
|
|
b9b275a897 | ||
|
|
d3b9fed9c2 | ||
|
|
685f9aae97 | ||
|
|
55f6bc8367 | ||
|
|
e1c3bba14b | ||
|
|
348a57a4a4 | ||
|
|
ccc32c3164 | ||
|
|
cf60e54647 | ||
|
|
990834ab6c | ||
|
|
536b6ace35 | ||
|
|
d99169da2d | ||
|
|
8ffd3fb0ba | ||
|
|
f3c3646c81 | ||
|
|
605d9da512 | ||
|
|
4f00962a81 | ||
|
|
2eaff04946 | ||
|
|
2b69c15226 | ||
|
|
b7a19efa46 | ||
|
|
06a8b870c0 | ||
|
|
e4f79f6e98 | ||
|
|
87a910a127 | ||
|
|
364fea3ca0 | ||
|
|
fcca65bbe5 | ||
|
|
dade777e6d | ||
|
|
1bf68a978b | ||
|
|
4329721384 | ||
|
|
f77b644797 | ||
|
|
22e59c4da0 | ||
|
|
51a4d3090f | ||
|
|
f54ec7caf1 | ||
|
|
3e8ac82cbb | ||
|
|
bac82a954f | ||
|
|
2066643243 | ||
|
|
7460b4382c | ||
|
|
3d7dfc7068 | ||
|
|
abdf894edf | ||
|
|
42086bee57 | ||
|
|
eb9e5803b1 | ||
|
|
59eb2b19ac | ||
|
|
eb1f9b02f7 | ||
|
|
6e50206adf | ||
|
|
77db64ef2c | ||
|
|
28a1835ce4 | ||
|
|
9ce2c2179f | ||
|
|
3fbcfdb9ea | ||
|
|
dc9364c137 |
4
.github/ISSUE_TEMPLATE.md
vendored
4
.github/ISSUE_TEMPLATE.md
vendored
@@ -5,7 +5,7 @@
|
||||
- [ ] Suggestion
|
||||
- OS
|
||||
- [ ] Linux
|
||||
- [ ] Mac OS X
|
||||
- [ ] macOS
|
||||
- [ ] 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/vimrc)
|
||||
vim -Nu <(curl https://gist.githubusercontent.com/junegunn/6936bf79fedd3a079aeb1dd2f3c81ef5/raw)
|
||||
|
||||
-->
|
||||
|
||||
|
||||
70
README.md
70
README.md
@@ -29,12 +29,23 @@ 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 fzf currently does not compile on Windows.
|
||||
note that Windows support is experimental at the moment.
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
Using [vim-plug](https://github.com/junegunn/vim-plug):
|
||||
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:
|
||||
|
||||
```vim
|
||||
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
|
||||
@@ -43,8 +54,6 @@ 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
|
||||
@@ -93,6 +102,10 @@ 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 = {
|
||||
@@ -107,6 +120,7 @@ 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 =
|
||||
@@ -117,6 +131,7 @@ 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'],
|
||||
@@ -133,12 +148,6 @@ 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
|
||||
|
||||
@@ -152,18 +161,47 @@ let g:fzf_tags_command = 'ctags -R'
|
||||
let g:fzf_commands_expect = 'alt-enter,ctrl-x'
|
||||
```
|
||||
|
||||
#### Advanced customization using autoload functions
|
||||
#### Advanced customization
|
||||
|
||||
You can use autoload functions to define your own commands.
|
||||
|
||||
```vim
|
||||
" git grep
|
||||
" Command for git grep
|
||||
" - fzf#vim#grep(command, with_column, [options], [fullscreen])
|
||||
command! -bang -nargs=* GGrep
|
||||
\ call fzf#vim#grep('git grep --line-number '.shellescape(<q-args>), 0, <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'})
|
||||
" 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)
|
||||
```
|
||||
|
||||
Mappings
|
||||
@@ -222,7 +260,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 not allowed
|
||||
- `sink` or `sink*` are ignored
|
||||
|
||||
#### Reducer example
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
" Copyright (c) 2016 Junegunn Choi
|
||||
" Copyright (c) 2017 Junegunn Choi
|
||||
"
|
||||
" MIT License
|
||||
"
|
||||
@@ -28,10 +28,83 @@ set cpo&vim
|
||||
" Common
|
||||
" ------------------------------------------------------------------
|
||||
|
||||
let s:is_win = has('win32') || has('win64')
|
||||
let s:layout_keys = ['window', 'up', 'down', 'left', 'right']
|
||||
let s:TYPE = {'dict': type({}), 'funcref': type(function('call')), 'string': type('')}
|
||||
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
|
||||
|
||||
function s:remove_layout(opts)
|
||||
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)
|
||||
for key in s:layout_keys
|
||||
if has_key(a:opts, key)
|
||||
call remove(a:opts, key)
|
||||
@@ -45,15 +118,14 @@ 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)
|
||||
if get(opts, 'options', '') !~ '--expect' && has_key(opts, 'sink*')
|
||||
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*')
|
||||
let Sink = remove(opts, 'sink*')
|
||||
let wrapped = fzf#wrap(a:name, opts, a:bang)
|
||||
let wrapped['sink*'] = Sink
|
||||
@@ -75,10 +147,6 @@ 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)
|
||||
@@ -91,9 +159,12 @@ 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, 'cterm')
|
||||
if code =~ '^[0-9]\+$'
|
||||
let code = synIDattr(synIDtrans(hlID(group)), a:attr, fam)
|
||||
if code =~? pat
|
||||
return code
|
||||
endif
|
||||
endfor
|
||||
@@ -102,11 +173,19 @@ 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 = (empty(fg) ? s:ansi[a:default] : ('38;5;'.fg)) .
|
||||
\ (empty(bg) ? '' : (';48;5;'.bg))
|
||||
let color = s:csi(empty(fg) ? s:ansi[a:default] : fg, 1) .
|
||||
\ (empty(bg) ? '' : s:csi(bg, 0))
|
||||
return printf("\x1b[%s%sm%s\x1b[m", color, a:0 ? ';1' : '', a:str)
|
||||
endfunction
|
||||
|
||||
@@ -117,13 +196,7 @@ for s:color_name in keys(s:ansi)
|
||||
endfor
|
||||
|
||||
function! s:buflisted()
|
||||
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)
|
||||
return filter(range(1, bufnr('$')), 'buflisted(v:val) && getbufvar(v:val, "&filetype") != "qf"')
|
||||
endfunction
|
||||
|
||||
function! s:fzf(name, opts, extra)
|
||||
@@ -143,7 +216,7 @@ function! s:fzf(name, opts, extra)
|
||||
|
||||
let eopts = has_key(extra, 'options') ? remove(extra, 'options') : ''
|
||||
let merged = extend(copy(a:opts), extra)
|
||||
let merged.options = join(filter([s:defaults(), get(merged, 'options', ''), eopts], '!empty(v:val)'))
|
||||
call s:merge_opts(merged, eopts)
|
||||
return fzf#run(s:wrap(a:name, merged, bang))
|
||||
endfunction
|
||||
|
||||
@@ -152,6 +225,12 @@ 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
|
||||
@@ -181,7 +260,7 @@ function! s:warn(message)
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
function! s:uniq(list)
|
||||
function! fzf#vim#_uniq(list)
|
||||
let visited = {}
|
||||
let ret = []
|
||||
for l in a:list
|
||||
@@ -196,19 +275,30 @@ 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 = {'options': '-m '.get(g:, 'fzf_files_options', '')}
|
||||
let args = {}
|
||||
if !empty(a:dir)
|
||||
if !isdirectory(expand(a:dir))
|
||||
return s:warn('Invalid directory')
|
||||
endif
|
||||
let dir = substitute(a:dir, '/*$', '/', '')
|
||||
let slash = (s:is_win && !&shellslash) ? '\\' : '/'
|
||||
let dir = substitute(a:dir, '[/\\]*$', slash, '')
|
||||
let args.dir = dir
|
||||
let args.options .= ' --prompt '.shellescape(dir)
|
||||
else
|
||||
let args.options .= ' --prompt '.shellescape(pathshorten(getcwd())).'/'
|
||||
let dir = s:shortpath()
|
||||
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
|
||||
|
||||
@@ -220,7 +310,7 @@ function! s:line_handler(lines)
|
||||
return
|
||||
endif
|
||||
normal! m'
|
||||
let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], '')
|
||||
let cmd = s:action_for(a:lines[0])
|
||||
if !empty(cmd) && stridx('edit', cmd) < 0
|
||||
execute 'silent' cmd
|
||||
endif
|
||||
@@ -289,7 +379,7 @@ function! s:buffer_line_handler(lines)
|
||||
return
|
||||
endif
|
||||
normal! m'
|
||||
let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], '')
|
||||
let cmd = s:action_for(a:lines[0])
|
||||
if !empty(cmd)
|
||||
execute 'silent' cmd
|
||||
endif
|
||||
@@ -317,9 +407,12 @@ 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': map(split(globpath(&rtp, "colors/*.vim"), "\n"),
|
||||
\ "substitute(fnamemodify(v:val, ':t'), '\\..\\{-}$', '', '')"),
|
||||
\ 'source': fzf#vim#_uniq(map(colors, "substitute(fnamemodify(v:val, ':t'), '\\..\\{-}$', '', '')")),
|
||||
\ 'sink': 'colo',
|
||||
\ 'options': '+m --prompt="Colors> "'
|
||||
\}, a:000)
|
||||
@@ -339,9 +432,11 @@ endfunction
|
||||
" History[:/]
|
||||
" ------------------------------------------------------------------
|
||||
function! s:all_files()
|
||||
return extend(
|
||||
\ filter(reverse(copy(v:oldfiles)), "filereadable(expand(v:val))"),
|
||||
\ filter(map(s:buflisted(), 'bufname(v:val)'), '!empty(v:val)'))
|
||||
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, ":~:.")'))
|
||||
endfunction
|
||||
|
||||
function! s:history_source(type)
|
||||
@@ -395,8 +490,8 @@ endfunction
|
||||
|
||||
function! fzf#vim#history(...)
|
||||
return s:fzf('history-files', {
|
||||
\ 'source': reverse(s:all_files()),
|
||||
\ 'options': '-m --prompt "Hist> "'
|
||||
\ 'source': s:all_files(),
|
||||
\ 'options': ['-m', '--header-lines', !empty(expand('%')), '--prompt', 'Hist> ']
|
||||
\}, a:000)
|
||||
endfunction
|
||||
|
||||
@@ -404,14 +499,7 @@ 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
|
||||
@@ -423,7 +511,7 @@ function! fzf#vim#gitfiles(args, ...)
|
||||
endif
|
||||
if a:args != '?'
|
||||
return s:fzf('gfiles', {
|
||||
\ 'source': 'git ls-files '.a:args,
|
||||
\ 'source': 'git ls-files '.a:args.(s:is_win ? '' : ' | uniq'),
|
||||
\ 'dir': root,
|
||||
\ 'options': '-m --prompt "GitFiles> "'
|
||||
\}, a:000)
|
||||
@@ -435,7 +523,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..,.. --prompt "GitFiles?> " --preview ''sh -c "(git diff --color=always -- {-1} | sed 1,4d; cat {-1}) | head -500"'''
|
||||
\ 'options': ['--ansi', '--multi', '--nth', '2..,..', '--tiebreak=index', '--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*')
|
||||
@@ -482,7 +570,7 @@ function! s:bufopen(lines)
|
||||
return
|
||||
endif
|
||||
endif
|
||||
let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], '')
|
||||
let cmd = s:action_for(a:lines[0])
|
||||
if !empty(cmd)
|
||||
execute 'silent' cmd
|
||||
endif
|
||||
@@ -503,16 +591,21 @@ 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
|
||||
return b1 < b2 ? 1 : -1
|
||||
endfunction
|
||||
|
||||
function! s:buflisted_sorted()
|
||||
return sort(s:buflisted(), 's:sort_buffers')
|
||||
endfunction
|
||||
|
||||
function! fzf#vim#buffers(...)
|
||||
let bufs = map(sort(s:buflisted(), 's:sort_buffers'), 's:format_buffer(v:val)')
|
||||
let [query, args] = (a:0 && type(a:1) == type('')) ?
|
||||
\ [a:1, a:000[1:]] : ['', a:000]
|
||||
return s:fzf('buffers', {
|
||||
\ 'source': reverse(bufs),
|
||||
\ 'source': map(s:buflisted_sorted(), 's:format_buffer(v:val)'),
|
||||
\ 'sink*': s:function('s:bufopen'),
|
||||
\ 'options': '+m -x --tiebreak=index --header-lines=1 --ansi -d "\t" -n 2,1..2 --prompt="Buf> "',
|
||||
\}, a:000)
|
||||
\ 'options': '+m -x --tiebreak=index --header-lines=1 --ansi -d "\t" -n 2,1..2 --prompt="Buf> "'.s:q(query)
|
||||
\}, args)
|
||||
endfunction
|
||||
|
||||
" ------------------------------------------------------------------
|
||||
@@ -533,7 +626,7 @@ function! s:ag_handler(lines, with_column)
|
||||
return
|
||||
endif
|
||||
|
||||
let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], 'e')
|
||||
let cmd = s:action_for(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
|
||||
@@ -565,12 +658,15 @@ 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 . ' ' . s:q1(query)
|
||||
let command = ag_opts . ' ' . fzf#shellescape(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
|
||||
|
||||
@@ -586,13 +682,12 @@ 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 opts = {
|
||||
\ 'source': a:grep_command,
|
||||
\ 'column': a:with_column,
|
||||
\ 'options': '--ansi --delimiter : --nth '.textcol.',.. --prompt "'.capname.'> " '.
|
||||
\ '--multi --bind alt-a:select-all,alt-d:deselect-all '.
|
||||
\ '--color hl:68,hl+:110'
|
||||
\ 'options': ['--ansi', '--prompt', capname.'> ',
|
||||
\ '--multi', '--bind', 'alt-a:select-all,alt-d:deselect-all',
|
||||
\ '--color', 'hl:68,hl+:110']
|
||||
\}
|
||||
function! opts.sink(lines)
|
||||
return s:ag_handler(a:lines, self.column)
|
||||
@@ -611,7 +706,7 @@ function! s:btags_source(tag_cmds)
|
||||
|
||||
for cmd in a:tag_cmds
|
||||
let lines = split(system(cmd), "\n")
|
||||
if !v:shell_error
|
||||
if !v:shell_error && len(lines)
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
@@ -628,7 +723,7 @@ function! s:btags_sink(lines)
|
||||
return
|
||||
endif
|
||||
normal! m'
|
||||
let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], '')
|
||||
let cmd = s:action_for(a:lines[0])
|
||||
if !empty(cmd)
|
||||
execute 'silent' cmd '%'
|
||||
endif
|
||||
@@ -647,15 +742,20 @@ function! s:btags_sink(lines)
|
||||
endfunction
|
||||
|
||||
function! s:q(query)
|
||||
return ' --query '.s:q1(a:query)
|
||||
return ' --query '.fzf#shellescape(a:query)
|
||||
endfunction
|
||||
|
||||
" query, [[tag commands], options]
|
||||
function! fzf#vim#buffer_tags(query, ...)
|
||||
let args = copy(a:000)
|
||||
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'))]
|
||||
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
|
||||
try
|
||||
return s:fzf('btags', {
|
||||
\ 'source': s:btags_source(tag_cmds),
|
||||
@@ -675,14 +775,17 @@ function! s:tags_sink(lines)
|
||||
endif
|
||||
normal! m'
|
||||
let qfl = []
|
||||
let cmd = get(get(g:, 'fzf_action', s:default_action), a:lines[0], 'e')
|
||||
let cmd = s:action_for(a:lines[0], 'e')
|
||||
try
|
||||
let [magic, &magic, wrapscan, &wrapscan] = [&magic, 0, &wrapscan, 1]
|
||||
let [magic, &magic, wrapscan, &wrapscan, acd, &acd] = [&magic, 0, &wrapscan, 1, &acd, 0]
|
||||
for line in a:lines[1:]
|
||||
try
|
||||
let parts = split(line, '\t\zs')
|
||||
let excmd = matchstr(join(parts[2:], ''), '^.*\ze;"\t')
|
||||
call s:open(cmd, parts[1][:-2])
|
||||
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))
|
||||
execute excmd
|
||||
call add(qfl, {'filename': expand('%'), 'lnum': line('.'), 'text': getline('.')})
|
||||
catch /^Vim:Interrupt$/
|
||||
@@ -692,7 +795,7 @@ function! s:tags_sink(lines)
|
||||
endtry
|
||||
endfor
|
||||
finally
|
||||
let [&magic, &wrapscan] = [magic, wrapscan]
|
||||
let [&magic, &wrapscan, &acd] = [magic, wrapscan, acd]
|
||||
endtry
|
||||
if len(qfl) > 1
|
||||
call setqflist(qfl)
|
||||
@@ -704,6 +807,9 @@ 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
|
||||
@@ -711,9 +817,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'))
|
||||
call system(get(g:, 'fzf_tags_command', 'ctags -R'.(s:is_win ? ' --output-format=e-ctags' : '')))
|
||||
if empty(tagfiles())
|
||||
return s:warn('Failed to create tags')
|
||||
endif
|
||||
@@ -722,21 +828,20 @@ function! fzf#vim#tags(query, ...)
|
||||
endif
|
||||
endif
|
||||
|
||||
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
|
||||
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 ' : ''
|
||||
|
||||
return s:fzf('tags', {
|
||||
\ 'source': proc.shellescape(fnamemodify(tagfile, ':t')),
|
||||
\ 'source': fzf#shellescape(s:bin.tags).' '.join(map(tagfiles, 'fzf#shellescape(fnamemodify(v:val, ":p"))')),
|
||||
\ 'sink*': s:function('s:tags_sink'),
|
||||
\ 'dir': fnamemodify(tagfile, ':h'),
|
||||
\ 'options': copt.'-m --tiebreak=begin --prompt "Tags> "'.s:q(a:query)}, a:000)
|
||||
\ 'options': opts.'--nth 1..2 -m --tiebreak=begin --prompt "Tags> "'.s:q(a:query)}, a:000)
|
||||
endfunction
|
||||
|
||||
" ------------------------------------------------------------------
|
||||
@@ -839,7 +944,7 @@ 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], '')
|
||||
let cmd = s:action_for(a:lines[0])
|
||||
if !empty(cmd)
|
||||
execute 'silent' cmd
|
||||
endif
|
||||
@@ -870,14 +975,22 @@ function! s:helptag_sink(line)
|
||||
endfunction
|
||||
|
||||
function! fzf#vim#helptags(...)
|
||||
let sorted = sort(split(globpath(&runtimepath, '**/doc/tags'), '\n'))
|
||||
let tags = exists('*uniq') ? uniq(sorted) : s:uniq(sorted)
|
||||
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)
|
||||
|
||||
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, 'shellescape(v:val)')).
|
||||
\ "| perl -ne '/(.*?):(.*?)\t(.*?)\t/; printf(qq(".s:green('%-40s', 'Label')."\t%s\t%s\n), $2, $3, $1)' | sort",
|
||||
\ 'source': 'grep -H ".*" '.join(map(tags, 'fzf#shellescape(v:val)')).
|
||||
\ ' | perl -n '.fzf#shellescape(s:helptags_script).' | 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
|
||||
|
||||
" ------------------------------------------------------------------
|
||||
@@ -934,12 +1047,13 @@ function! s:commits_sink(lines)
|
||||
return
|
||||
endif
|
||||
|
||||
let cmd = get(extend({'ctrl-d': ''}, get(g:, 'fzf_action', s:default_action)), a:lines[0], 'e')
|
||||
let diff = a:lines[0] == 'ctrl-d'
|
||||
let cmd = s:action_for(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}')
|
||||
let sha = matchstr(a:lines[idx], '[0-9a-f]\{7,9}')
|
||||
if !empty(sha)
|
||||
if empty(cmd)
|
||||
if diff
|
||||
if idx > 1
|
||||
execute 'tab sb' buf
|
||||
endif
|
||||
@@ -959,11 +1073,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', '--graph --color=always --format="%C(auto)%h%d %s %C(green)%cr"')
|
||||
let current = expand('%:S')
|
||||
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 managed = 0
|
||||
if !empty(current)
|
||||
call system('git show '.current.' 2> /dev/null')
|
||||
call system('git show '.fzf#shellescape(current).' 2> '.(s:is_win ? 'nul' : '/dev/null'))
|
||||
let managed = !v:shell_error
|
||||
endif
|
||||
|
||||
@@ -971,7 +1085,9 @@ function! s:commits(buffer_local, args)
|
||||
if !managed
|
||||
return s:warn('The current buffer is not in the working tree')
|
||||
endif
|
||||
let source .= ' --follow '.current
|
||||
let source .= ' --follow '.fzf#shellescape(current)
|
||||
else
|
||||
let source .= ' --graph'
|
||||
endif
|
||||
|
||||
let command = a:buffer_local ? 'BCommits' : 'Commits'
|
||||
@@ -979,15 +1095,20 @@ function! s:commits(buffer_local, args)
|
||||
let options = {
|
||||
\ 'source': source,
|
||||
\ 'sink*': s:function('s:commits_sink'),
|
||||
\ 'options': '--ansi --multi --no-sort --tiebreak=index --reverse '.
|
||||
\ '--inline-info --prompt "'.command.'> " --bind=ctrl-s:toggle-sort '.
|
||||
\ '--expect='.expect_keys
|
||||
\ '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]
|
||||
\ }
|
||||
|
||||
if a:buffer_local
|
||||
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"'
|
||||
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'])
|
||||
endif
|
||||
|
||||
return s:fzf(a:buffer_local ? 'bcommits' : 'commits', options, a:args)
|
||||
@@ -1043,13 +1164,12 @@ function! fzf#vim#maps(mode, ...)
|
||||
let list = []
|
||||
let curr = ''
|
||||
for line in split(cout, "\n")
|
||||
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]), '/')
|
||||
if line =~ "^\t"
|
||||
let src = ' '.join(reverse(reverse(split(split(line)[-1], '/'))[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)
|
||||
@@ -1076,7 +1196,7 @@ endfunction
|
||||
|
||||
function! s:complete_trigger()
|
||||
let opts = copy(s:opts)
|
||||
let opts.options = printf('+m -q %s %s', shellescape(s:query), get(opts, 'options', ''))
|
||||
call s:prepend_opts(opts, ['+m', '-q', s:query])
|
||||
let opts['sink*'] = s:function('s:complete_insert')
|
||||
let s:reducer = s:pluck(opts, 'reducer', s:function('s:first_line'))
|
||||
call fzf#run(opts)
|
||||
@@ -1121,16 +1241,20 @@ endfunction
|
||||
|
||||
function! fzf#vim#complete(...)
|
||||
if a:0 == 0
|
||||
let s:opts = g:fzf#vim#default_layout
|
||||
let s:opts = fzf#wrap()
|
||||
elseif type(a:1) == s:TYPE.dict
|
||||
if has_key(a:1, 'sink') || has_key(a:1, 'sink*')
|
||||
echoerr 'sink not allowed'
|
||||
return ''
|
||||
endif
|
||||
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
|
||||
let s:opts = extend({'source': a:1}, g:fzf#vim#default_layout)
|
||||
echoerr 'Invalid argument: '.string(a:000)
|
||||
return ''
|
||||
endif
|
||||
for s in ['sink', 'sink*']
|
||||
if has_key(s:opts, s)
|
||||
call remove(s:opts, s)
|
||||
endif
|
||||
endfor
|
||||
|
||||
let eol = col('$')
|
||||
let ve = &ve
|
||||
@@ -1153,8 +1277,14 @@ 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')
|
||||
let s:opts.options =
|
||||
\ join(filter([get(s:opts, 'options', ''), remove(s:opts, 'extra_options')], '!empty(v:val)'))
|
||||
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
|
||||
endif
|
||||
|
||||
call feedkeys("\<Plug>(-fzf-complete-trigger)")
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
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)
|
||||
@@ -48,7 +49,7 @@ endif
|
||||
function! fzf#vim#complete#word(...)
|
||||
return fzf#vim#complete(s:extend({
|
||||
\ 'source': 'cat /usr/share/dict/words'},
|
||||
\ get(a:000, 0, g:fzf#vim#default_layout)))
|
||||
\ get(a:000, 0, fzf#wrap())))
|
||||
endfunction
|
||||
|
||||
" ----------------------------------------------------------------------------
|
||||
@@ -58,25 +59,26 @@ 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, '/*$', '/', ''),
|
||||
\ substitute(a:prefix, '[/\\]*$', slash, ''),
|
||||
\ ''] :
|
||||
\ [fnamemodify(expanded, ':h'),
|
||||
\ substitute(fnamemodify(a:prefix, ':h'), '/*$', '/', ''),
|
||||
\ substitute(fnamemodify(a:prefix, ':h'), '[/\\]*$', slash, ''),
|
||||
\ 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:^:%s:'",
|
||||
\ shellescape(dir), empty(a:prefix) || a:prefix == tail ? '' : head)
|
||||
\ "cd %s && ".s:file_cmd." | sed %s",
|
||||
\ fzf#shellescape(dir), fzf#shellescape('s:^:'.(empty(a:prefix) || a:prefix == tail ? '' : head).':'))
|
||||
endfunction
|
||||
|
||||
function! s:file_options(prefix)
|
||||
let [_, head, tail] = s:file_split_prefix(a:prefix)
|
||||
return printf('--prompt %s --query %s', shellescape(head), shellescape(tail))
|
||||
return ['--prompt', head, '--query', tail]
|
||||
endfunction
|
||||
|
||||
function! s:fname_prefix(str)
|
||||
@@ -128,7 +130,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, g:fzf#vim#default_layout)))
|
||||
\ 'options': s:function('s:file_options')}, get(a:000, 0, fzf#wrap())))
|
||||
endfunction
|
||||
|
||||
" ----------------------------------------------------------------------------
|
||||
@@ -147,13 +149,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, g:fzf#vim#default_layout)))
|
||||
\ 'reducer': s:function('s:reduce_line')}, get(a:000, 0, fzf#wrap())))
|
||||
endfunction
|
||||
|
||||
function! fzf#vim#complete#buffer_line(...)
|
||||
call fzf#vim#complete(s:extend({
|
||||
return fzf#vim#complete(s:extend({
|
||||
\ 'prefix': '^.*$',
|
||||
\ 'source': s:uniq(getline(1, '$'))}, get(a:000, 0, g:fzf#vim#default_layout)))
|
||||
\ 'source': fzf#vim#_uniq(getline(1, '$'))}, get(a:000, 0, fzf#wrap())))
|
||||
endfunction
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
|
||||
57
bin/preview.rb
Executable file
57
bin/preview.rb
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env ruby
|
||||
#
|
||||
# usage: ./preview.rb [-v] FILENAME[:LINE][:IGNORED]
|
||||
|
||||
require 'shellwords'
|
||||
|
||||
COMMAND = %[(highlight -O ansi -l {} || coderay {} || rougify {} || 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
|
||||
offset = [1, center - height / 3].max
|
||||
|
||||
IO.popen(['sh', '-c', COMMAND.gsub('{}', Shellwords.shellescape(path))]) 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
|
||||
else
|
||||
puts line
|
||||
end
|
||||
end
|
||||
end
|
||||
57
bin/preview.sh
Executable file
57
bin/preview.sh
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/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
|
||||
15
bin/tags.pl
Executable file
15
bin/tags.pl
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/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;
|
||||
}
|
||||
137
doc/fzf-vim.txt
137
doc/fzf-vim.txt
@@ -1,4 +1,4 @@
|
||||
fzf-vim.txt fzf-vim Last change: September 20 2015
|
||||
fzf-vim.txt fzf-vim Last change: October 21 2017
|
||||
FZF-VIM - TABLE OF CONTENTS *fzf-vim* *fzf-vim-toc*
|
||||
==============================================================================
|
||||
|
||||
@@ -8,10 +8,14 @@ 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*
|
||||
@@ -53,35 +57,48 @@ 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 fzf currently does not compile on Windows.
|
||||
note that Windows support is experimental at the moment.
|
||||
|
||||
|
||||
INSTALLATION *fzf-vim-installation*
|
||||
==============================================================================
|
||||
|
||||
Using {vim-plug}{4}:
|
||||
Use {vim-plug}{4} or any Vim plugin manager of your choice.
|
||||
|
||||
If you already installed fzf using {Homebrew}{5}, the following should
|
||||
suffice:
|
||||
>
|
||||
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': 'yes \| ./install' }
|
||||
Plug '/usr/local/opt/fzf'
|
||||
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 (git ls-files)
|
||||
`GFiles?` | Git files (git status)
|
||||
`GFiles [OPTS]` | Git files ( `git ls-files` )
|
||||
`GFiles?` | Git files ( `git status` )
|
||||
`Buffers` | Open buffers
|
||||
`Colors` | Color schemes
|
||||
`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
|
||||
`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
|
||||
`Tags [QUERY]` | Tags in the project ( `ctags -R` )
|
||||
`BTags [QUERY]` | Tags in the current buffer
|
||||
`Marks` | Marks
|
||||
@@ -90,36 +107,40 @@ COMMANDS *fzf-vim-commands*
|
||||
`History` | `v:oldfiles` and open buffers
|
||||
`History:` | Command history
|
||||
`History/` | Search history
|
||||
`Snippets` | Snippets ({UltiSnips}{6})
|
||||
`Commits` | Git commits (requires {fugitive.vim}{7})
|
||||
`Snippets` | Snippets ({UltiSnips}{7})
|
||||
`Commits` | Git commits (requires {fugitive.vim}{8})
|
||||
`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. `let g: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}{8}.
|
||||
(1: `Helptags` will shadow the command of the same name from {pathogen}{9}.
|
||||
But its functionality is still available via `call pathogen#helptags()`.)
|
||||
|
||||
{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
|
||||
{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
|
||||
|
||||
|
||||
< 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 = {
|
||||
@@ -134,6 +155,7 @@ Global options~
|
||||
" 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 =
|
||||
@@ -144,6 +166,7 @@ Global options~
|
||||
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
|
||||
\ 'hl+': ['fg', 'Statement'],
|
||||
\ 'info': ['fg', 'PreProc'],
|
||||
\ 'border': ['fg', 'Ignore'],
|
||||
\ 'prompt': ['fg', 'Conditional'],
|
||||
\ 'pointer': ['fg', 'Exception'],
|
||||
\ 'marker': ['fg', 'Keyword'],
|
||||
@@ -156,21 +179,20 @@ Global options~
|
||||
" 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'
|
||||
@@ -179,19 +201,48 @@ Command-local options~
|
||||
let g:fzf_commands_expect = 'alt-enter,ctrl-x'
|
||||
<
|
||||
|
||||
Advanced customization using autoload functions~
|
||||
Advanced customization~
|
||||
*fzf-vim-advanced-customization*
|
||||
|
||||
You can use autoload functions to define your own commands.
|
||||
>
|
||||
" git grep
|
||||
" Command for git grep
|
||||
" - fzf#vim#grep(command, with_column, [options], [fullscreen])
|
||||
command! -bang -nargs=* GGrep
|
||||
\ call fzf#vim#grep('git grep --line-number '.shellescape(<q-args>), 0, <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'})
|
||||
<
|
||||
" 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)
|
||||
<
|
||||
|
||||
MAPPINGS *fzf-vim-mappings*
|
||||
==============================================================================
|
||||
@@ -251,7 +302,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 not allowed
|
||||
- `sink` or `sink*` are ignored
|
||||
|
||||
|
||||
Reducer example~
|
||||
@@ -268,6 +319,20 @@ 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*
|
||||
==============================================================================
|
||||
|
||||
|
||||
@@ -23,8 +23,7 @@
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
let g:fzf#vim#default_layout = {'down': '~40%'}
|
||||
let s:is_win = has('win32') || has('win64')
|
||||
|
||||
function! s:defs(commands)
|
||||
let prefix = get(g:, 'fzf_command_prefix', '')
|
||||
@@ -33,32 +32,35 @@ function! s:defs(commands)
|
||||
return
|
||||
endif
|
||||
for command in a:commands
|
||||
execute substitute(command, '\ze\C[A-Z]', prefix, '')
|
||||
let name = ':'.prefix.matchstr(command, '\C[A-Z]\S\+')
|
||||
if 2 != exists(name)
|
||||
execute substitute(command, '\ze\C[A-Z]', prefix, '')
|
||||
endif
|
||||
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! -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)'])
|
||||
\'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)'])
|
||||
|
||||
function! s:history(arg, bang)
|
||||
let bang = a:bang || a:arg[len(a:arg)-1] == '!'
|
||||
@@ -81,13 +83,13 @@ if has('nvim') && get(g:, 'fzf_nvim_statusline', 1)
|
||||
doautocmd User FzfStatusLine
|
||||
else
|
||||
if $TERM !~ "256color"
|
||||
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
|
||||
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
|
||||
else
|
||||
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
|
||||
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
|
||||
endif
|
||||
setlocal statusline=%#fzf1#\ >\ %#fzf2#fz%#fzf3#f
|
||||
endif
|
||||
@@ -122,9 +124,14 @@ augroup fzf_buffers
|
||||
augroup END
|
||||
|
||||
inoremap <expr> <plug>(fzf-complete-word) fzf#vim#complete#word()
|
||||
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 ''")
|
||||
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-line) fzf#vim#complete#line()
|
||||
inoremap <expr> <plug>(fzf-complete-buffer-line) fzf#vim#complete#buffer_line()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user