:vnoremap <f4> c<c-r>=Template(@")<cr><esc>

might do the trick for you.

It seems to almost work. I would actually like to yank the text and not
change it, but the real problem is if I do as above and define the
Template as below only to test that it works I alsways get an extra 0.

        function! Template(text)
                execute "normal! o>" . a:text . "<"
        endfunction

I mean if I mark the word:
        house
        
Then I get:
        >house0<
What is this 0?

The zero is what is the return value of the function which is used as the replacement text. By default, if you don't specify a return-value for a function, it returns "0".

I was expecting your function's return value/purpose was what you wanted the replaced text to be. Perhaps if you detail some of what your function is doing, it would help diagnose matters.

However with the mapping I suggested, for the time being, you likely want either

function! Template(text)
        " do some stuff with a:text, such as
        " look it up in a dictionary,
        " update another window,
        " do some match/syn highlighting, etc
        return a:text
        " return the text unchanged
endfunction

or you want to do your manipulations on the text and return the result:

function! Template(text)
        return '>'.(a:text).'<'
endfunction


Hope this helps explain where that 0 was coming from and how the mapping worked.

-tim



Reply via email to