Friday, October 2, 2015

Re: Looking for a robust 'search for visual selection' implementation

Hello,

----- Mail original -----
> one popular implementation of a 'search for the current visual
> selection' mapping looks like this:
> I was wondering if anybody can point me to a small, robust
> implementation that handles all the edge cases properly and doesn't
> have side effects, before I try to write one myself.

In plugin/v_start.vim from lh-misc (https://github.com/LucHermitte/lh-misc/blob/master/plugin/v_star.vim), you'll find a version that leaves the register used untouched. However, the search register is modified, which is a feature.

This plugin uses lh#visual#selection() function from lh-vim-lib.

I can't tell about null bytes, I've never encountered them.

The complete code would look like:

xnoremap <silent> * <c-\><c-n>/<c-r>=escape(lh#visual#selection(), '/\^$*.[~')<cr><cr>
xnoremap <silent> # <c-\><c-n>?<c-r>=escape(lh#visual#selection(), '?\^$*.[~')<cr><cr>

function! lh#visual#selection()
try
let a_save = @a
normal! gv"ay
return @a
finally
let @a = a_save
endtry
endfunction

HTH,

--
Luc Hermitte

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: