From 9430765116eb0c8cc4bb6dea48f481257126c1c7 Mon Sep 17 00:00:00 2001 From: bretello Date: Wed, 9 Dec 2020 00:59:20 +0100 Subject: [PATCH] vim: fix visual selection commands - use gs to run fugitive's Git show on the selected text (must be a git ref) - use k to run ack on the selected text --- vim/functions.vim | 9 +++++++-- vim/shortcuts.vim | 12 +++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/vim/functions.vim b/vim/functions.vim index b1dd7e3..19844d0 100644 --- a/vim/functions.vim +++ b/vim/functions.vim @@ -64,6 +64,11 @@ function! CmdLine(str) call feedkeys(":" . a:str) endfunction +" Call Git show on the selected text (must be a git ref) +function! GitShowVisual() range + execute "Git show " . @* +endfunction + function! VisualSelection(direction, extra_filter) range let l:saved_reg = @" execute "normal! vgvy" @@ -71,8 +76,8 @@ function! VisualSelection(direction, extra_filter) range let l:pattern = escape(@", "\\/.*'$^~[]") let l:pattern = substitute(l:pattern, "\n$", "", "") - if a:direction == 'gv' - call CmdLine("Ack '" . l:pattern . "' " ) + if a:direction == 'ack' + call CmdLine("Ack '" . l:pattern . "' ") elseif a:direction == 'replace' call CmdLine("%s" . '/'. l:pattern . '/') endif diff --git a/vim/shortcuts.vim b/vim/shortcuts.vim index 5ef9c99..18acc97 100644 --- a/vim/shortcuts.vim +++ b/vim/shortcuts.vim @@ -70,9 +70,6 @@ nmap h :ALEHover nmap r :ALERename map ` :ALELint -" call ack when pressing gv in visual -vnoremap gv :call VisualSelection('gv', '') - map nn :NERDTreeToggle map o :BufExplorer @@ -85,7 +82,7 @@ map b :CtrlPBuffer map f :CtrlPMRUFiles map t :CtrlPTag - +"Misc stuff let s:uname='' let s:uname = system('uname | tr -d "\n"') " Get platform name (stripping the trailing newline) if s:uname == "Darwin" @@ -107,6 +104,11 @@ noremap p "*p noremap Y "+y noremap P "+p - " A friggin python breakpoint. Invoke with @b "FIXME: make this decent let @b = 'A breakpoint()€ýajkj0' + + +" visual mode mappings +vnoremap k :call VisualSelection('ack', '') +vnoremap gs :call GitShowVisual() +vnoremap r :call VisualSelection('replace', '')