I'm defining a Vim function:
function! HelloWorld() range
echo "hello world"
endfunction
I open a text file with many lines with vim -u NONE filename.txt, jump to the last line with G, and call HelloWorld() with :%call HelloWorld(). I notice the cursor jumps to the first line. How to prevent this, i.e. keeping the cursor at current line? Thanks a lot!
P.S. The function mentioned above is just a minimal example. I know the problem disappears if I remove the range and call with :call HelloWorld(), but it's needed in my actual problem.
Edit:
function! HelloWorld() range
let l:win_view = winsaveview()
echo "hello world"
call winrestview(l:win_view)
endfunction
won't work.