Hi!

For example, I do often want to
replace a name in the text with another. What I used to do is
selecting it with mouse and type
:%s/<ctrl-ins>/newname/gc
Is there a way to do this with the mouse (and without retyping the name) ?
What I want is maybe something like 'invoking a yanked register in my
colon command'

I have the following in my vimrc file:

function MakeSearchString(str)
    return substitute(escape(@", '\\/.*$^~[]'), '\n', '\\n', 'g')
endfunction

function! <SID>VisualSearch(direction)
    if a:direction == '#'
        let l:rhs = "y?"
    else
        let l:rhs = "y/"
    endif
    let l:rhs = l:rhs . "\<C-R>=MakeSearchString(@\")\<CR>\<CR>gV"
    return l:rhs
endfunction

vnoremap <expr> * <SID>VisualSearch('*')
vnoremap <expr> # <SID>VisualSearch('#')

vnoremap <F3> y/<C-R>=MakeSearchString(@")<CR>
vnoremap <S-F3> y?<C-R>=MakeSearchString(@")<CR>
vnoremap <M-F3> y:%s/<C-R>=MakeSearchString(@")<CR>/

With this just select a text and by typing <F3> you can search for the selected text and by typing <M-F3> you can replace it easily. '*' searches forward and '#' backwards like '*' and '#' do for the word under the cursor in normal mode.

Best regards,
Georg





Reply via email to