nvim: plugin/visual-star-search: Use custom visual star search
neovim enabled search selection by * and # in visual mode but seems that is not good enough. https://github.com/neovim/neovim/pull/18538#pullrequestreview-971039192 Add and use Justin Keyes version referenced above.
This commit is contained in:
parent
21944d6bca
commit
edb11e5e1d
1 changed files with 23 additions and 0 deletions
23
nvim/.config/nvim/plugin/visual-star-search.vim
Normal file
23
nvim/.config/nvim/plugin/visual-star-search.vim
Normal file
|
@ -0,0 +1,23 @@
|
|||
func! s:get_visual_selection_list() abort
|
||||
let [lnum1, col1] = getpos("'<")[1:2]
|
||||
let [lnum2, col2] = getpos("'>")[1:2]
|
||||
let lines = getline(lnum1, lnum2)
|
||||
let lines[-1] = lines[-1][: col2 - (&selection ==? 'inclusive' ? 1 : 2)]
|
||||
let lines[0] = lines[0][col1 - 1:]
|
||||
return lines
|
||||
endf
|
||||
|
||||
func! s:get_visual_selection_searchpattern() abort
|
||||
let lines = s:get_visual_selection_list()
|
||||
let lines = map(lines, 'escape(v:val, ''/\'')')
|
||||
" Join with a _literal_ \n to make a valid search pattern.
|
||||
return join(lines, '\n')
|
||||
endf
|
||||
|
||||
" Read last visual-selection into command line
|
||||
cnoremap <c-r><c-v> <c-r>=join(<sid>get_visual_selection_list(), " ")<cr>
|
||||
inoremap <c-r><c-v> <c-r>=join(<sid>get_visual_selection_list(), " ")<cr>
|
||||
|
||||
xnoremap * <esc>ms/\V<c-r>=<sid>get_visual_selection_searchpattern()<cr><cr>
|
||||
nnoremap <silent> * ms:<c-u>let @/='\V\<'.escape(expand('<cword>'), '/\').'\>'<bar>call histadd('/',@/)<bar>set hlsearch<cr>
|
||||
nnoremap <silent> g* ms:<c-u>let @/='\V' . escape(expand('<cword>'), '/\') <bar>call histadd('/',@/)<bar>set hlsearch<cr>
|
Loading…
Reference in a new issue