From 0e995e191390e8654114bca187c0318f7decb8eb Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 31 Oct 2015 00:33:06 +0900 Subject: [PATCH 1/3] Customizable statusline Close #32 --- README.md | 15 +++++++++++++++ plugin/fzf.vim | 27 ++++++++++++++++----------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 108bc7c..3c6b3f2 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,21 @@ inoremap fzf#complete({ \ 'left': 20}) ``` +Status line (neovim) +-------------------- + +```vim +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 fzf_statusline() +``` + License ------- diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 64ce688..89f36d3 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -79,14 +79,19 @@ endfunction if has('nvim') && get(g:, 'fzf_nvim_statusline', 1) function! s:fzf_restore_colors() - if $TERM !~ "256color" - highlight fzf1 ctermfg=1 ctermbg=8 - highlight fzf2 ctermfg=2 ctermbg=8 - highlight fzf3 ctermfg=7 ctermbg=8 + if exists('#User#FzfStatusLine') + doautocmd User FzfStatusLine else - highlight fzf1 ctermfg=161 ctermbg=238 - highlight fzf2 ctermfg=151 ctermbg=238 - highlight fzf3 ctermfg=252 ctermbg=238 + if $TERM !~ "256color" + highlight fzf1 ctermfg=1 ctermbg=8 + highlight fzf2 ctermfg=2 ctermbg=8 + highlight fzf3 ctermfg=7 ctermbg=8 + else + highlight fzf1 ctermfg=161 ctermbg=238 + highlight fzf2 ctermfg=151 ctermbg=238 + highlight fzf3 ctermfg=252 ctermbg=238 + endif + setlocal statusline=%#fzf1#\ >\ %#fzf2#fz%#fzf3#f endif endfunction @@ -96,13 +101,13 @@ if has('nvim') && get(g:, 'fzf_nvim_statusline', 1) endif setlocal nospell - setlocal statusline=%#fzf1#\ >\ %#fzf2#fz%#fzf3#f + call s:fzf_restore_colors() endfunction - augroup fzf_statusline + augroup _fzf_statusline autocmd! - autocmd TermOpen *bin/fzf* call s:fzf_nvim_term() | autocmd WinEnter call s:fzf_nvim_term() - autocmd VimEnter,ColorScheme * call s:fzf_restore_colors() + autocmd FileType fzf call s:fzf_nvim_term() + \| autocmd WinEnter,ColorScheme call s:fzf_restore_colors() augroup END endif From 1a2d597045525b9ed0046cc38333deaa27eec7b8 Mon Sep 17 00:00:00 2001 From: Ilia Choly Date: Fri, 30 Oct 2015 12:05:54 -0400 Subject: [PATCH 2/3] Add GitFiles command --- README.md | 1 + autoload/fzf/vim.vim | 12 ++++++++++++ doc/fzf-vim.txt | 1 + plugin/fzf.vim | 1 + 4 files changed, 15 insertions(+) diff --git a/README.md b/README.md index 3c6b3f2..392bf8a 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ Commands | Command | List | | --- | --- | | `Files [PATH]` | Files (similar to `:FZF`) | +| `GitFiles` | Git files | `Buffers` | Open buffers | | `Colors` | Color schemes | | `Ag [PATTERN]` | [ag][ag] search result (`CTRL-A` to select all, `CTRL-D` to deselect all) | diff --git a/autoload/fzf/vim.vim b/autoload/fzf/vim.vim index e3a90ce..8a028d4 100644 --- a/autoload/fzf/vim.vim +++ b/autoload/fzf/vim.vim @@ -323,6 +323,18 @@ function! fzf#vim#history(...) \}, a:000) endfunction +" ------------------------------------------------------------------ +" GitFiles +" ------------------------------------------------------------------ + +function! fzf#vim#gitfiles(...) + call s:fzf({ + \ 'source': 'git ls-tree --name-only -r HEAD', + \ 'sink*': s:function('s:common_sink'), + \ 'options': '--prompt "GitFiles> " -m'.s:expect(), + \}, a:000) +endfunction + " ------------------------------------------------------------------ " Buffers " ------------------------------------------------------------------ diff --git a/doc/fzf-vim.txt b/doc/fzf-vim.txt index d5bc06a..2427965 100644 --- a/doc/fzf-vim.txt +++ b/doc/fzf-vim.txt @@ -75,6 +75,7 @@ COMMANDS *fzf-vim-commands* Command | List ~ -----------------+--------------------------------------------------------------------- `Files [PATH]` | Files (similar to `:FZF` ) + `GitFiles` | Git files `Buffers` | Open buffers `Colors` | Color schemes `Ag [PATTERN]` | {ag}{5} search result (CTRL-A to select all, CTRL-D to deselect all) diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 89f36d3..c4f0673 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -43,6 +43,7 @@ endfunction call s:defs([ \'command! -bang -nargs=? -complete=dir Files call fzf#vim#files(, s:w(0))', +\'command! -bang GitFiles call fzf#vim#gitfiles(s:w(0))', \'command! -bang Buffers call fzf#vim#buffers(s:w(0))', \'command! -bang Lines call fzf#vim#lines(s:w(0))', \'command! -bang BLines call fzf#vim#buffer_lines(s:w(0))', From 7d5154ae680f8713938435943d9a8fddabefee0d Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Mon, 2 Nov 2015 10:17:56 +0900 Subject: [PATCH 3/3] [GitFiles] List files from project root --- autoload/fzf/vim.vim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/autoload/fzf/vim.vim b/autoload/fzf/vim.vim index 8a028d4..42bc72b 100644 --- a/autoload/fzf/vim.vim +++ b/autoload/fzf/vim.vim @@ -328,8 +328,14 @@ endfunction " ------------------------------------------------------------------ function! fzf#vim#gitfiles(...) + let root = systemlist('git rev-parse --show-toplevel')[0] + if v:shell_error + call s:warn('Not in git repo') + return + endif call s:fzf({ \ 'source': 'git ls-tree --name-only -r HEAD', + \ 'dir': root, \ 'sink*': s:function('s:common_sink'), \ 'options': '--prompt "GitFiles> " -m'.s:expect(), \}, a:000)