I need to write a function that returns current visually selected text or
<cword> on mapping. Result of this function I give further to
cscope find s command. Something like this:
noremap <C-\>s :call <SID>Run_cscope(<SID>get_vselect_or_cword())<CR> func s:Run_cscope(pattern) exe 'cs find s ' . a:pattern endfunc func s:get_vselect_or_cword() let vselect = s:get_visual_selection() if vselect != '' let pattern = vselect else let pattern = expand("<cword>") endif return pattern endfunc
The question is how to write
get_visual_selection() function? Another words how to get current visually selected text? I have found some solutions in this question but all of them are not appropriate because
get_visual_selection() returns previous visually selected text if nothing selected. I need that it returns
'' in this case. It seems that solution should be very easy, but I don't really experienced in vimscript and just not see it.