FuzzyOpen improvements
9853ddf5ea437a103de4df5641560fc6977addc1
1 parent
8e9b28cf
.vimrc
+9 -4
| 158 | 158 | if has("nvim") |
|
| 159 | 159 | tnoremap <Esc> <C-\><C-n> |
|
| 160 | 160 | endif |
|
| 161 | 161 | ||
| 162 | 162 | command! FuzzyOpen call s:fuzzy() |
|
| 163 | - | function! s:fuzzy() |
|
| 163 | + | function! s:fuzzy() abort |
|
| 164 | 164 | let lines = 12 |
|
| 165 | 165 | let tmp = tempname() |
|
| 166 | 166 | let command = "ag -g '' | fzy -l " . lines . " > " . tmp |
|
| 167 | 167 | let opts = { 'tmp': tmp } |
|
| 168 | 168 | ||
| 169 | - | function! opts.on_exit(id, code) |
|
| 169 | + | function! opts.on_exit(id, code) abort |
|
| 170 | 170 | bdelete! |
|
| 171 | 171 | if a:code == 0 |
|
| 172 | 172 | if filereadable(self.tmp) |
|
| 173 | 173 | let result = readfile(self.tmp) |
|
| 174 | 174 | if !empty(result) |
| 178 | 178 | endif |
|
| 179 | 179 | endfunction |
|
| 180 | 180 | ||
| 181 | 181 | below new |
|
| 182 | 182 | execute 'resize' lines + 1 |
|
| 183 | - | call termopen(command, opts) |
|
| 184 | - | file FuzzyOpen |
|
| 183 | + | ||
| 184 | + | if bufnr('FuzzyOpen') > 0 |
|
| 185 | + | execute 'buffer' bufnr('FuzzyOpen') |
|
| 186 | + | else |
|
| 187 | + | call termopen(command, opts) |
|
| 188 | + | file FuzzyOpen |
|
| 189 | + | endif |
|
| 185 | 190 | startinsert |
|
| 186 | 191 | endfunction |
|
| 187 | 192 | ||
| 188 | 193 | if executable('ag') |
|
| 189 | 194 | let g:ackprg = 'ag --vimgrep' |