* David Fishburn [2006.10.18 22:00]:
> " Courtesy of Michael Naumann, Jürgen Krämer
> " Visually select text, then search for it
> if version >= 602
>     " Here are two enhanced versions of these mappings which use VIM 6.2's
>     " getregtype() function to determine whether the unnamed register
> contains
>     " a characterwise, linewise or blockwise selection. After the search has
> 
>     " been executed, the register *and* its type can then be restored with
>     " setreg().
>     vnoremap <silent> * :<C-U>
>                   \let old_reg=getreg('"')<bar>
>                   \let old_regmode=getregtype('"')<cr>
>                   \gvy/<C-R><C-R>=substitute(substitute(
>                   \escape(@", '\\/.*$^~[]' ), "\n$", "", ""),
>                   \"\n", '\\_[[:return:]]', "g")<cr><cr>
>                   \:call setreg('"', old_reg, old_regmode)<cr>
>     vnoremap <silent> # :<C-U>
>                   \let old_reg=getreg('"')<bar>
>                   \let old_regmode=getregtype('"')<cr>
>                   \gvy?<C-R><C-R>=substitute(substitute(
>                   \escape(@", '\\/.*$^~[]' ), "\n$", "", ""),
>                   \"\n", '\\_[[:return:]]', "g")<cr><cr>
>                   \:call setreg('"', old_reg, old_regmode)<cr>
> else
>     " If you use both VIM 6.2 and older versions these mappings
>     " should be defined depending on the current version.
>     vnoremap <silent> * :<C-U>let old_reg=@"<cr>
>                   \gvy/<C-R><C-R>=substitute(substitute(
>                   \escape(@", '\\/.*$^~[]' ), "\n$", "", ""),
>                   \"\n", '\\_[[:return:]]', "g")<cr><cr>
>                   \:let @"=old_reg<cr>
>     vnoremap <silent> # :<C-U>let old_reg=@"<cr>
>                   \gvy?<C-R><C-R>=substitute(substitute(
>                   \escape(@", '\\/.*$^~[]' ), "\n$", "", ""),
>                   \"\n", '\\_[[:return:]]', "g")<cr><cr>
>                   \:let @"=old_reg<cr>
> endif

This is where I got my inspiration. Note the exact
same credits. But I found the mappings so
illegible that I rewrote them as functions. 

I don't find using a function to be much of a
"con" compare to the "pro" of legibility. The
function I posted today has already been hacked
and made better. It would take much more time and
thought to modify these monsters...

Reading the comments at the top, I thought for a
minute that the mapping could search for a
blockwise visual region. That would be pretty
neat.

-- 
JR

Reply via email to