vim:keys: Only map v_* & v_# if they don't exist

I learned just now that neovim added mappings for these by default in
v0.8.0. But instead of checking for neovim, check for the existence of
mappings in case vim adds these in the future too.
This commit is contained in:
2025-09-17 23:33:16 +02:00
parent 5b8f54b0cb
commit 0a5b6d0767

View File

@@ -124,8 +124,12 @@ function! GetVisualSelection(escape = "", byteescape = 'n')
return l:sel
endfunction
vmap * /\V<C-R>=GetVisualSelection('/\')<CR><CR>
vmap # ?\V<C-R>=GetVisualSelection('?\')<CR><CR>
" In case these do not exist already (At the time of writing only Neovim adds
" mappings for these)
if maparg('*', 'v', 0, 1) == {}
vmap * /\V<C-R>=GetVisualSelection('/\')<CR><CR>
vmap # ?\V<C-R>=GetVisualSelection('?\')<CR><CR>
endif
" Extended `*`. Starts vim search (without jump) and ripgrep
nmap <leader>* :let @/ = '\<' . expand('<cword>') . '\>' <bar>