vim:keys: Fix newline and tab search for v_*
Multiline search didn't work previously when searching with v_* and tabs were ignored when searching with v_<leader>*.
This commit is contained in:
@@ -109,25 +109,33 @@ endif
|
|||||||
|
|
||||||
" Search for selected text.
|
" Search for selected text.
|
||||||
" Modified from https://vim.fandom.com/wiki/Search_for_visually_selected_text
|
" Modified from https://vim.fandom.com/wiki/Search_for_visually_selected_text
|
||||||
function! GetVisualSelection()
|
function! GetVisualSelection(escape = "", byteescape = 'n')
|
||||||
let l:old_reg = getreg('"')
|
let l:old_reg = getreg('"')
|
||||||
let l:old_regtype = getregtype('"')
|
let l:old_regtype = getregtype('"')
|
||||||
norm gvy
|
norm gvy
|
||||||
let l:sel = getreg('"')
|
let l:sel = getreg('"')
|
||||||
call setreg('"', l:old_reg, l:old_regtype)
|
call setreg('"', l:old_reg, l:old_regtype)
|
||||||
|
|
||||||
|
let l:sel = l:sel->escape(a:escape)
|
||||||
|
for l:char in a:byteescape
|
||||||
|
let l:sel = l:sel->substitute('\'..l:char, '\\'..l:char, 'g')
|
||||||
|
endfor
|
||||||
|
|
||||||
return l:sel
|
return l:sel
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
vmap * /\V<C-R>=escape(GetVisualSelection(),'/\')<CR><CR>
|
vmap * /\V<C-R>=GetVisualSelection('/\')<CR><CR>
|
||||||
vmap # ?\V<C-R>=escape(GetVisualSelection(),'?\')<CR><CR>
|
vmap # ?\V<C-R>=GetVisualSelection('?\')<CR><CR>
|
||||||
|
|
||||||
" Extended `*`. Starts vim search (without jump) and ripgrep
|
" Extended `*`. Starts vim search (without jump) and ripgrep
|
||||||
nmap <leader>* :let @/ = '\<' . expand('<cword>') . '\>' <bar>
|
nmap <leader>* :let @/ = '\<' . expand('<cword>') . '\>' <bar>
|
||||||
\ set hlsearch <bar>
|
\ set hlsearch <bar>
|
||||||
\ Rg \b<C-R>=expand('<cword>')<CR>\b<CR>
|
\ Rg \b<C-R>=expand('<cword>')<CR>\b<CR>
|
||||||
vmap <leader>* :<C-U>let @/ = "\\V<C-R>=escape(escape(GetVisualSelection(), '\'), '"\')<CR>" <bar>
|
" TODO: pass --multiline to rg when multiple lines selected
|
||||||
|
" TODO: Use ^ and $ anchors in visual-line mode
|
||||||
|
vmap <leader>* :<C-U>let @/ = "\\V<C-R>=escape(GetVisualSelection('\'), '"\')<CR>" <bar>
|
||||||
\ set hlsearch <bar>
|
\ set hlsearch <bar>
|
||||||
\ Rg <C-R>=escape(GetVisualSelection(), '.\[]<bar>*+?{}^$()')<CR><CR>
|
\ Rg <C-R>=GetVisualSelection('.\[]<bar>*+?{}^$()', 'nt')<CR><CR>
|
||||||
nmap <leader>g* :let @/ = expand('<cword>') <bar>
|
nmap <leader>g* :let @/ = expand('<cword>') <bar>
|
||||||
\ set hlsearch <bar>
|
\ set hlsearch <bar>
|
||||||
\ Rg <C-R>=expand('<cword>')<CR><CR>
|
\ Rg <C-R>=expand('<cword>')<CR><CR>
|
||||||
@@ -439,7 +447,7 @@ vnoremap <leader><C-L> gu
|
|||||||
" `ExpandVisualSelection(1)` which results in a block selection that spans over
|
" `ExpandVisualSelection(1)` which results in a block selection that spans over
|
||||||
" all other TODOs as well.
|
" all other TODOs as well.
|
||||||
function! ExpandVisualSelection(direction)
|
function! ExpandVisualSelection(direction)
|
||||||
let l:sel = escape(GetVisualSelection(), '\')
|
let l:sel = GetVisualSelection('\')
|
||||||
normal gv
|
normal gv
|
||||||
|
|
||||||
" Move the cursor onto the side of the selection that points in the
|
" Move the cursor onto the side of the selection that points in the
|
||||||
|
|||||||
Reference in New Issue
Block a user