vim: fix visual selection commands

- use <leader>gs to run fugitive's Git show on the selected text
 (must be a git ref)
- use <leader>k to run ack on the selected text
feature/symbol-search
bretello 2020-12-09 00:59:20 +01:00
parent 34fd5a8726
commit 9430765116
Signed by: brethil
GPG Key ID: 876AAC6290170FE7
2 changed files with 14 additions and 7 deletions

View File

@ -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

View File

@ -70,9 +70,6 @@ nmap <leader>h :ALEHover<CR>
nmap <leader>r :ALERename<CR>
map <leader>` :ALELint<CR>
" call ack when pressing gv in visual
vnoremap <silent> gv :call VisualSelection('gv', '')<CR>
map <leader>nn :NERDTreeToggle<CR>
map <leader>o :BufExplorer<CR>
@ -85,7 +82,7 @@ map <leader>b :CtrlPBuffer<CR>
map <leader>f :CtrlPMRUFiles<CR>
map <leader>t :CtrlPTag<CR>
"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 <Leader>p "*p
noremap <Leader>Y "+y
noremap <Leader>P "+p
" A friggin python breakpoint. Invoke with @b "FIXME: make this decent
let @b = 'A breakpoint()€ýajkj0'
" visual mode mappings
vnoremap <silent> <leader>k :call VisualSelection('ack', '')<CR>
vnoremap <silent> <leader>gs :call GitShowVisual()<CR>
vnoremap <silent> <leader>r :call VisualSelection('replace', '')<CR>