This question already has an answer here:
- Way to get content of Visual Selection? 3 answers
Having some text selected in visual mode, I need some way of turning it into a string that can be used in an expression.
I have tried this
function! VisualSelection() normal! `<""y`> return @" endfunction
and it works by itself, but when I want to use it in a mapping vim complains because of the
normal command, which, guess what, can't be used in mappings with
<expr>, so I need some different way of doing this.
I've found out that it is possible to find mark positions with regex like
\%'> but I don't know how to find regex in the file in an expression (
match wants a string, and I haven't found any similar function that searches in the file itself)