diff --git a/README.md b/README.md index 5b382d3d..f51a754a 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,8 @@ To add your own Vim, Tmux or Zsh plugin you can just clone it to proper * [editorconfig-vim](https://github.com/editorconfig/editorconfig-vim): EditorConfig plugin for Vim * [fzf.vim](https://github.com/junegunn/fzf.vim): fzf :heart: vim + * [fzf-contrib](https://github.com/deathbeam/dotfiles/tree/master/vim/.vim/bundle/fzf-contrib): + Completion menu using FZF, tab-completion, support for `ripgrep` in FZF * [syntastic](https://github.com/scrooloose/syntastic): Syntax checking hacks for vim * [tsuquyomi](https://github.com/Quramy/tsuquyomi): A Vim plugin for TypeScript diff --git a/vim/.vim/bundle/editorconfig-vim b/vim/.vim/bundle/editorconfig-vim index d5c4d6dc..26781c57 160000 --- a/vim/.vim/bundle/editorconfig-vim +++ b/vim/.vim/bundle/editorconfig-vim @@ -1 +1 @@ -Subproject commit d5c4d6dc5bee51b467fbc01a141d073e9b108918 +Subproject commit 26781c577da740786a4d1723ddaddfef79701e32 diff --git a/vim/.vim/bundle/fzf-contrib/autoload/fzf/contrib.vim b/vim/.vim/bundle/fzf-contrib/autoload/fzf/contrib.vim new file mode 100644 index 00000000..91c29ccf --- /dev/null +++ b/vim/.vim/bundle/fzf-contrib/autoload/fzf/contrib.vim @@ -0,0 +1,56 @@ +function! fzf#contrib#complete(findstart, base) + let Func = function(get(g:, 'fzf#contrib#completefunc', &omnifunc)) + let results = Func(a:findstart, a:base) + echom a:base + + if a:findstart + return results + endif + + let words = type(results) == type({}) && has_key(results, 'words') + \ ? map(results.words, 'v:val.word . "\t" . v:val.menu') + \ : results + + let results = fzf#run({ + \ 'source': words, + \ 'down': '~40%', + \ 'options': printf('--query "%s" +s -m', a:base) + \ }) + + if exists('*UltiSnips#ExpandSnippet') + \ && len(results) == 1 + \ && len(results[0]) > 1 + \ && match(split(results[0], "\t")[1], '\[snip\]') != -1 + call feedkeys("\=UltiSnips#ExpandSnippet()\") + endif + + return map(results, 'split(v:val, "\t")[0]') +endfunction + +function! fzf#contrib#trigger_complete() + setlocal completefunc=fzf#contrib#complete + setlocal completeopt=menu + call feedkeys("\\", 'n') +endfunction + +function! fzf#contrib#tab_complete() + let col = col('.') - 1 + + if !col || getline('.')[col - 1] !~# '\k' + call feedkeys("\", 'n') + else + call fzf#contrib#trigger_complete() + endif +endfunction + +function! fzf#contrib#grep(query, ...) + if executable('rg') + let query = empty(a:query) ? '^.' : a:query + let args = copy(a:000) + let opts = len(args) > 1 ? remove(args, 0) : '' + let command = opts . ' ' . "'".substitute(query, "'", "'\\\\''", 'g')."'" + return call('fzf#vim#grep', extend(['rg --no-heading --column --color always '.command, 1], args)) + endif + + return call('fzf#vim#ag', insert(copy(a:000), a:query, 0)) +endfunction diff --git a/vim/.vim/bundle/fzf-contrib/plugin/fzf-contrib.vim b/vim/.vim/bundle/fzf-contrib/plugin/fzf-contrib.vim new file mode 100644 index 00000000..517e4b1d --- /dev/null +++ b/vim/.vim/bundle/fzf-contrib/plugin/fzf-contrib.vim @@ -0,0 +1,3 @@ +imap :call fzf#contrib#trigger_complete() +inoremap :call fzf#contrib#tab_complete() +command! -bang -nargs=* Grep call fzf#contrib#grep(, 0) diff --git a/vim/.vim/bundle/tsuquyomi b/vim/.vim/bundle/tsuquyomi index 8ef3976c..72681b0b 160000 --- a/vim/.vim/bundle/tsuquyomi +++ b/vim/.vim/bundle/tsuquyomi @@ -1 +1 @@ -Subproject commit 8ef3976c58df2446f778fd49d95b58a0fe8b4db7 +Subproject commit 72681b0be0415fa406894c712090ef4db27a0b69 diff --git a/vim/.vim/bundle/vim-snippets b/vim/.vim/bundle/vim-snippets index c5694771..1b183d06 160000 --- a/vim/.vim/bundle/vim-snippets +++ b/vim/.vim/bundle/vim-snippets @@ -1 +1 @@ -Subproject commit c569477189f02ded61a3fc3c3f43abcc1ebcdaa4 +Subproject commit 1b183d063738a30a13113261273215b89e2842f2 diff --git a/vim/.vim/bundle/vim-test b/vim/.vim/bundle/vim-test index 9bcdb4f0..c3ed265f 160000 --- a/vim/.vim/bundle/vim-test +++ b/vim/.vim/bundle/vim-test @@ -1 +1 @@ -Subproject commit 9bcdb4f013c15a515479f060e89ff690b3993973 +Subproject commit c3ed265f314f03c3d729cac7957246267dadb6e9 diff --git a/vim/.vimrc b/vim/.vimrc index f5ad6bde..e2dafd9b 100644 --- a/vim/.vimrc +++ b/vim/.vimrc @@ -30,6 +30,21 @@ if has('clipboard') set clipboard=unnamedplus endif +" use syntax complete if nothing else available +autocmd VimRc Filetype * + \ if &omnifunc == "" + \| setlocal omnifunc=syntaxcomplete#Complete + \| endif + +" Use faster grep alternatives if possible +if executable('rg') + set grepprg=rg\ --vimgrep\ --no-heading + set grepformat^=%f:%l:%c:%m +elseif executable('ag') + set grepprg=ag\ --nogroup\ --nocolor\ --vimgrep + set grepformat^=%f:%l:%c:%m +endif + " }}} " User interface {{{ @@ -134,21 +149,6 @@ set synmaxcol=256 " Automatically rebalance windows on vim resize autocmd VimRc VimResized * :wincmd = -" use syntax complete if nothing else available -autocmd VimRc Filetype * - \ if &omnifunc == "" - \| setlocal omnifunc=syntaxcomplete#Complete - \| endif - -" Use faster grep alternatives if possible -if executable('rg') - set grepprg=rg\ --vimgrep\ --no-heading - set grepformat^=%f:%l:%c:%m -elseif executable('ag') - set grepprg=ag\ --nogroup\ --nocolor\ --vimgrep - set grepformat^=%f:%l:%c:%m -endif - " }}} " Colors {{{ @@ -205,7 +205,7 @@ set fileformats=unix,dos,mac " }}} -" Mappings {{{ +" Mappings and commands {{{ " With a map leader it's possible to do extra key combinations let mapleader = ' ' @@ -302,85 +302,14 @@ let g:syntastic_check_on_wq = 0 set statusline+=%#warningmsg#%{SyntasticStatuslineFlag()}%* " Vim Test -let test#strategy = 'make' +let g:test#strategy = 'make' nmap mt :TestFile nmap mT :TestSuite nmap mtt :TestNearest -" FZF {{{ - -" Fuzzy completion -function! FuzzyCompleteFunc(findstart, base) - let Func = function(get(g:, 'fuzzyfunc', &omnifunc)) - let results = Func(a:findstart, a:base) - - if a:findstart - return results - endif - - if type(results) == type({}) && has_key(results, 'words') - let l:words = [] - for result in results.words - call add(words, result.word . ' ' . result.menu) - endfor - elseif len(results) - let l:words = results - endif - - if len(l:words) - let result = fzf#run({ 'source': l:words, 'down': '~40%', 'options': printf('--query "%s" +s', a:base) }) - - if empty(result) - return [ a:base ] - endif - - return [ split(result[0])[0] ] - else - return [ a:base ] - endif -endfunction - -let g:fuzzyfunc = 'completor#completefunc' - -" Custom trigger for our fuzzy function -function! FuzzyFuncTrigger() - setlocal completefunc=FuzzyCompleteFunc - setlocal completeopt=menu - call feedkeys("\\", 'n') -endfunction - -imap :call FuzzyFuncTrigger() - -" Awesome TAB fuzzy completion -function! TabComplete() - let col = col('.') - 1 - - if !col || getline('.')[col - 1] !~# '\k' - call feedkeys("\", 'n') - return - endif - - call feedkeys("\\") -endfunction - -inoremap :call TabComplete() - -" Try to use ripgrep, otherwise fallback to ag -function! s:fzf_rg(query, ...) - if executable('rg') - let query = empty(a:query) ? '^.' : a:query - let args = copy(a:000) - let opts = len(args) > 1 ? remove(args, 0) : '' - let command = opts . ' ' . "'".substitute(query, "'", "'\\\\''", 'g')."'" - return call('fzf#vim#grep', extend(['rg --no-heading --column --color always '.command, 1], args)) - endif - - return call('fzf#vim#ag', insert(copy(a:000), a:query, 0)) -endfunction - -command! -bang -nargs=* Find call s:fzf_rg(, 0) - -nmap / :Find +" FZF +let g:fzf#contrib#completefunc = 'completor#completefunc' +nmap / :Grep nmap T :Tags nmap t :BTags nmap F :Files @@ -392,7 +321,6 @@ nmap w :Windows nmap s :Snippets nmap c :Commits nmap ? :Helptags -" }}} " }}}