Friday, October 2, 2015

Looking for a robust 'search for visual selection' implementation

Hi list,

one popular implementation of a 'search for the current visual
selection' mapping looks like this:

function! s:VSetSearch(cmdtype)
let temp = @s
norm! gv"sy
let @/ = '\V' . substitute(escape(@s, a:cmdtype.'\'), '\n', '\\n', 'g')
let @s = temp
endfunction

xnoremap * :<C-u>call <SID>VSetSearch('/')<CR>/<C-R>=@/<CR><CR>
xnoremap # :<C-u>call <SID>VSetSearch('?')<CR>?<C-R>=@/<CR><CR>

It does have a couple of problems though, such as not restoring the
register type of the s register, and not handling null bytes properly.

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.

Thanks,


--
David

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

Post a Comment