I know this must be something simple.
Why does vnoremap <leader>rl di[<esc>pa] wrap selected text in brackets, but:
vnoremap <leader>rl :call VisAddRefLink()<CR>
function! VisAddRefLink()
execute "normal! di[\<esc>pa]"
endfunction
doesn’t?!
Any help appreciated!
Try this:
The
<C-u>in front of thecallavoids that the mapping inserts the'<,'>visual range in front of it; we want the function called only one time, not once for every line in the range.Inside the function, we need to re-establish the visual selection first before operating on it; the
gvdoes that.