Hi,
Richard Emberson wrote:
> I've got the following visual maps which I use to do
> visual base searches:
>
> vmap F y?<C-R>"<CR>
> vmap f y/<C-R>"<CR>
>
> They work great, select some characters in visual mode and
> then enter 'f' (or 'F').
> The one caveat is if there are characters that have
> special meaning in searched such as the '[' ']' pair
> in the visual selection, then the search fails.
> Does anyone have a macro that will allow visual selection
> based searches that account for such special characters
> being in the selection?
this started as a macro, but to make use of the then new functions
getreg() and getregtype() I defined two helper functions:
if version >= 602
function! VisualSelection()
" Save register content and type.
let old_reg = getreg('"')
let old_regmode = getregtype('"')
" Calling this function has ended visual mode, so it must be started
" again before the selection can be yanked into the unnamed
register.
normal gvy
let selection = @"
" Restore register content and type.
call setreg('"', old_reg, old_regmode)
return selection
endfunction
else
function! VisualSelection()
" Save register content and type.
let old_reg = @"
" Calling this function has ended visual mode, so it must be started
" again before the selection can be yanked into the unnamed
register.
normal gvy
let selection = @"
" Restore register content and type.
let @" = old_reg
return selection
endfunction
endif
function! Escaped(text)
let result = escape(a:text, '\\/.*$^~[]')
let result = substitute(result, "\n$", "", "")
let result = substitute(result, "\n", '\\n', "g")
return result
endfunction
vnoremap <silent> * :<C-U><cr>/<C-R><C-R>=Escaped(VisualSelection())<cr><cr>
vnoremap <silent> # :<C-U><cr>?<C-R><C-R>=Escaped(VisualSelection())<cr><cr>
Regards,
Jürgen
--
Jürgen Krämer Softwareentwicklung
HABEL GmbH & Co. KG mailto:[EMAIL PROTECTED]
Hinteres Öschle 2 Tel: +49 / 74 61 / 93 53 - 15
78604 Rietheim-Weilheim Fax: +49 / 74 61 / 93 53 - 99