Fzf -> fzy
a7c25fbea7cc9f6705e566030524bf8a1392770f
Fzy actually matches based on what you type!
1 parent
bff029fa
.fzy.zsh
added
+46 -0
| 1 | + | # |
|
| 2 | + | # fzy shell integration |
|
| 3 | + | # |
|
| 4 | + | if [[ $- != *i* ]]; then |
|
| 5 | + | return |
|
| 6 | + | fi |
|
| 7 | + | ||
| 8 | + | __fzy_fsel () { |
|
| 9 | + | setopt localoptions pipefail 2> /dev/null |
|
| 10 | + | command ag -g '' | fzy | while read -r item; do |
|
| 11 | + | echo -n "${(q)item}" |
|
| 12 | + | done |
|
| 13 | + | local ret=$? |
|
| 14 | + | echo |
|
| 15 | + | return $ret |
|
| 16 | + | } |
|
| 17 | + | ||
| 18 | + | # Place the selected file path on the command line. |
|
| 19 | + | fzy-file-widget () { |
|
| 20 | + | LBUFFER="${LBUFFER}$(__fzy_fsel)" |
|
| 21 | + | local ret=$? |
|
| 22 | + | zle redisplay |
|
| 23 | + | typeset -f zle-line-init >/dev/null && zle zle-line-init |
|
| 24 | + | return $ret |
|
| 25 | + | } |
|
| 26 | + | zle -N fzy-file-widget |
|
| 27 | + | bindkey '^P' fzy-file-widget |
|
| 28 | + | ||
| 29 | + | # Place the selected command from history on the command line. |
|
| 30 | + | fzy-history-widget () { |
|
| 31 | + | local selected num |
|
| 32 | + | setopt localoptions noglobsubst pipefail 2> /dev/null |
|
| 33 | + | selected=( $(fc -l -r 1 | fzy -q "${LBUFFER//$/\\$}") ) |
|
| 34 | + | local ret=$? |
|
| 35 | + | if [[ -n ${selected} ]]; then |
|
| 36 | + | num=${selected[1]} |
|
| 37 | + | if [[ -n ${num} ]]; then |
|
| 38 | + | zle vi-fetch-history -n ${num} |
|
| 39 | + | fi |
|
| 40 | + | fi |
|
| 41 | + | zle redisplay |
|
| 42 | + | typeset -f zle-line-init >/dev/null && zle zle-line-init |
|
| 43 | + | return $ret |
|
| 44 | + | } |
|
| 45 | + | zle -N fzy-history-widget |
|
| 46 | + | bindkey '^R' fzy-history-widget |
.vimrc
+18 -21
| 145 | 145 | nnoremap <Up> :bprev<CR> |
|
| 146 | 146 | nnoremap <Down> :bnext<CR> |
|
| 147 | 147 | ||
| 148 | 148 | " Project search |
|
| 149 | 149 | nnoremap <C-f> :Ack!<Space> |
|
| 150 | + | nnoremap <C-p> :FuzzyOpen<CR> |
|
| 150 | 151 | ||
| 151 | 152 | map <Leader>m :make<CR> |
|
| 152 | - | map <C-p> :FuzzyOpen<CR> |
|
| 153 | 153 | map <C-_> <Plug>NERDCommenterToggle |
|
| 154 | 154 | map <Leader>. @: |
|
| 155 | 155 | map <Leader>e :e ~/.vimrc<CR> |
|
| 156 | 156 | map <Leader>s :source ~/.vimrc<CR> |
|
| 157 | 157 | ||
| 158 | - | " Fuzzy finder using `fzf`. Combines buffers with `ag`. |
|
| 159 | - | function! s:fuzzy(...) |
|
| 160 | - | try |
|
| 161 | - | let l = filter(range(1, bufnr('$')), 'buflisted(v:val)') |
|
| 162 | - | let buflist = filter(l, 'bufnr("") !~ v:val') |
|
| 163 | - | catch |
|
| 164 | - | let buflist = [] |
|
| 165 | - | endtry |
|
| 166 | - | ||
| 167 | - | let ag = split(system('ag --hidden -U -g ""'), '\n') |
|
| 168 | - | let bufs = map(buflist, 'bufname(v:val)') |
|
| 169 | - | let files = filter(ag, 'index(bufs, v:val) == -1') |
|
| 170 | - | let result = extend(files, bufs) |
|
| 171 | - | ||
| 172 | - | return fzf#run(fzf#wrap('buffers', { |
|
| 173 | - | \ 'source': reverse(result), |
|
| 174 | - | \ 'options': '--exact --color=16 --prompt="/ "', |
|
| 175 | - | \}), a:000) |
|
| 176 | - | endfunction |
|
| 177 | 158 | command! FuzzyOpen call s:fuzzy() |
|
| 159 | + | function! s:fuzzy() |
|
| 160 | + | let lines = 12 |
|
| 161 | + | let tmp = tempname() |
|
| 162 | + | let command = "ag -g '' | fzy -l " . lines . " > " . tmp |
|
| 163 | + | let opts = { 'tmp': tmp } |
|
| 164 | + | ||
| 165 | + | function! opts.on_exit(id, code) |
|
| 166 | + | close |
|
| 167 | + | let result = readfile(self.tmp) |
|
| 168 | + | execute 'edit' fnameescape(join(result)) |
|
| 169 | + | endfunction |
|
| 170 | + | ||
| 171 | + | below new |
|
| 172 | + | execute 'resize' lines + 1 |
|
| 173 | + | call termopen(command, opts) |
|
| 174 | + | startinsert |
|
| 175 | + | endfunction |
|
| 178 | 176 | ||
| 179 | 177 | if executable('ag') |
|
| 180 | 178 | let g:ackprg = 'ag --vimgrep' |
|
| 181 | 179 | endif |
|
| 182 | 180 |
| 197 | 195 | ||
| 198 | 196 | call plug#begin() |
|
| 199 | 197 | ||
| 200 | 198 | Plug 'scrooloose/nerdcommenter' |
|
| 201 | 199 | Plug 'airblade/vim-gitgutter' |
|
| 202 | - | Plug 'junegunn/fzf' |
|
| 203 | 200 | Plug 'tpope/vim-fugitive' |
|
| 204 | 201 | Plug 'mileszs/ack.vim' |
|
| 205 | 202 | Plug 'eagletmt/neco-ghc' |
|
| 206 | 203 | Plug 'shougo/deoplete.nvim' |
|
| 207 | 204 | Plug 'neovimhaskell/haskell-vim' |
.zshrc
+3 -13
| 1 | 1 | ## |
|
| 2 | 2 | # cloudhead - .zshrc |
|
| 3 | 3 | # |
|
| 4 | - | export FZF_DEFAULT_COMMAND='ag --hidden -U -g ""' |
|
| 5 | - | export FZF_DEFAULT_OPTS='--prompt="/ " --color=16,fg+:-1,hl+:-1,hl:254 --exact' |
|
| 6 | - | export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND" |
|
| 7 | - | ||
| 8 | 4 | [ -f ~/.profile ] && source ~/.profile |
|
| 9 | 5 | [ -f ~/.awsrc ] && source ~/.awsrc |
|
| 10 | 6 | ||
| 11 | - | # Should contain keybindings and completions for fzf |
|
| 12 | - | for f in ~/.fzf/*; do |
|
| 13 | - | source $f |
|
| 14 | - | done |
|
| 15 | - | ||
| 16 | 7 | # `ls` colors |
|
| 17 | 8 | if [ -f ~/.dircolors ]; then |
|
| 18 | 9 | eval $(dircolors -b ~/.dircolors) |
|
| 19 | 10 | fi |
|
| 20 | 11 |
| 26 | 17 | autoload -U complist |
|
| 27 | 18 | ||
| 28 | 19 | # Set input mode to vi |
|
| 29 | 20 | set -o vi |
|
| 30 | 21 | ||
| 31 | - | # Bind <C-r> to history search |
|
| 32 | - | if command -v fzf >/dev/null 2>&1; then |
|
| 33 | - | bindkey '^R' fzf-history-widget |
|
| 34 | - | bindkey '^P' fzf-file-widget |
|
| 22 | + | # Fzy integration |
|
| 23 | + | if command -v fzy >/dev/null 2>&1 && test -f ~/.fzy.zsh; then |
|
| 24 | + | source ~/.fzy.zsh |
|
| 35 | 25 | else |
|
| 36 | 26 | bindkey '^R' history-incremental-search-backward |
|
| 37 | 27 | fi |
|
| 38 | 28 | ||
| 39 | 29 | # |