summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2016-10-22 01:14:04 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2016-10-22 01:14:16 +0900
commit37f2d8f7952879bffd1326b88e4f0069ec1188d7 (patch)
treeb2422bb44a07cd187528fa64da5ddd207154bced
parent400e443a0a397e559250fa090b5c437e44d01bf8 (diff)
[vim] Respect g:fzf_colors
Close #711
-rw-r--r--README.md5
-rw-r--r--plugin/fzf.vim20
-rw-r--r--test/fzf.vader4
3 files changed, 26 insertions, 3 deletions
diff --git a/README.md b/README.md
index a5d2e954..ab57fb9a 100644
--- a/README.md
+++ b/README.md
@@ -319,7 +319,7 @@ Note that the environment variables `FZF_DEFAULT_COMMAND` and
`FZF_DEFAULT_OPTS` also apply here. Refer to [the wiki page][fzf-config] for
customization.
-[fzf-config]: https://github.com/junegunn/fzf/wiki/Configuring-FZF-command-(vim)
+[fzf-config]: https://github.com/junegunn/fzf/wiki/Configuring-Vim-plugin
#### `fzf#run`
@@ -347,7 +347,8 @@ page](https://github.com/junegunn/fzf/wiki/Examples-(vim)).
`fzf#wrap([name string,] [opts dict,] [fullscreen boolean])` is a helper
function that decorates the options dictionary so that it understands
-`g:fzf_layout`, `g:fzf_action`, and `g:fzf_history_dir` like `:FZF`.
+`g:fzf_layout`, `g:fzf_action`, `g:fzf_colors`, and `g:fzf_history_dir` like
+`:FZF`.
```vim
command! -bang MyStuff
diff --git a/plugin/fzf.vim b/plugin/fzf.vim
index 36a14802..96e30c44 100644
--- a/plugin/fzf.vim
+++ b/plugin/fzf.vim
@@ -159,6 +159,22 @@ function! s:common_sink(action, lines) abort
endtry
endfunction
+function! s:get_color(attr, ...)
+ for group in a:000
+ let code = synIDattr(synIDtrans(hlID(group)), a:attr, 'cterm')
+ if code =~ '^[0-9]\+$'
+ return code
+ endif
+ endfor
+ return ''
+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
+
" [name string,] [opts dict,] [fullscreen boolean]
function! fzf#wrap(...)
let args = ['', {}, 0]
@@ -190,8 +206,10 @@ function! fzf#wrap(...)
endif
endif
+ " Colors: g:fzf_colors
+ let opts.options = s:defaults() .' '. get(opts, 'options', '')
+
" History: g:fzf_history_dir
- let opts.options = get(opts, 'options', '')
if len(name) && len(get(g:, 'fzf_history_dir', ''))
let dir = expand(g:fzf_history_dir)
if !isdirectory(dir)
diff --git a/test/fzf.vader b/test/fzf.vader
index bab5c162..c6f899f0 100644
--- a/test/fzf.vader
+++ b/test/fzf.vader
@@ -143,6 +143,10 @@ Execute (fzf#wrap):
Assert opts.options =~ '--history /tmp/foobar'
Assert opts.options =~ '--color light'
+ let g:fzf_colors = { 'fg': ['fg', 'Error'] }
+ let opts = fzf#wrap({})
+ Assert opts.options =~ '^--color=fg:'
+
Execute (Cleanup):
unlet g:dir
Restore