commit b7da1dd9c5ca53df867efb77c5e43f667d57ee14
parent d735226de776f149c9c4b32e7f70acb8f18093c4
Author: Alex Balgavy <alex@balgavy.eu>
Date: Sat, 23 Apr 2022 15:09:35 +0200
vim: fzf for jumps and changes
Diffstat:
3 files changed, 57 insertions(+), 0 deletions(-)
diff --git a/vim/autoload/fzf_changes_jumps.vim b/vim/autoload/fzf_changes_jumps.vim
@@ -0,0 +1,44 @@
+function s:GoTo(jumpline)
+ let values = split(a:jumpline, ":")
+ execute "e ".values[0]
+ call cursor(str2nr(values[1]), str2nr(values[2]))
+ execute "normal zvzz"
+endfunction
+
+function s:GetLine(bufnr, lnum)
+ let lines = getbufline(a:bufnr, a:lnum)
+ if len(lines)>0
+ return trim(lines[0])
+ else
+ return ''
+ endif
+endfunction
+
+function! fzf_changes_jumps#Jumps()
+ " Get jumps with filename added
+ let jumps = map(reverse(copy(getjumplist()[0])),
+ \ { key, val -> extend(val, {'name': getbufinfo(val.bufnr)[0].name }) })
+
+ let jumptext = map(copy(jumps), { index, val ->
+ \ (val.name).':'.(val.lnum).':'.(val.col+1).': '.s:GetLine(val.bufnr, val.lnum) })
+
+ call fzf#run(fzf#vim#with_preview(fzf#wrap({
+ \ 'source': jumptext,
+ \ 'column': 1,
+ \ 'options': ['--delimiter', ':', '--bind', 'alt-a:select-all,alt-d:deselect-all', '--preview-window', '+{2}-/2'],
+ \ 'sink': function('s:GoTo')})))
+endfunction
+
+
+function! fzf_changes_jumps#Changes()
+ let changes = reverse(copy(getchangelist()[0]))
+
+ let changetext = map(copy(changes), { index, val ->
+ \ expand('%').':'.(val.lnum).':'.(val.col+1).': '.s:GetLine(bufnr('%'), val.lnum) })
+
+ call fzf#run(fzf#vim#with_preview(fzf#wrap({
+ \ 'source': changetext,
+ \ 'column': 1,
+ \ 'options': ['--delimiter', ':', '--bind', 'alt-a:select-all,alt-d:deselect-all', '--preview-window', '+{2}-/2'],
+ \ 'sink': function('s:GoTo')})))
+endfunction
diff --git a/vim/plugin/fzf_changes_jumps.vim b/vim/plugin/fzf_changes_jumps.vim
@@ -0,0 +1,9 @@
+if exists("g:loaded_fzf_changes_jumps") || &cp
+ finish
+endif
+
+let g:loaded_fzf_changes_jumps = 1
+command! Changes call fzf_changes_jumps#Changes()
+command! Jumps call fzf_changes_jumps#Jumps()
+nnoremap <Plug>FzfChangesJumpsChanges :Changes<CR>
+nnoremap <Plug>FzfChangesJumpsJumps :Jumps<CR>
diff --git a/vim/vimrc b/vim/vimrc
@@ -319,6 +319,10 @@ nnoremap <leader>/ :Ag<CR>
nnoremap <leader>M :Marks<CR>
nnoremap <leader>; :History:<CR>
+" My extensions
+nmap <leader>J <Plug>FzfChangesJumpsJumps
+nmap <leader>C <Plug>FzfChangesJumpsChanges
+
" Search for Todos/Fixmes
command! Todo Ag ((TO ?DO)|FIXME):?<space>?
nnoremap <leader>! :Todo<CR>