In vim, when executing a command with a range specified, the cursor will move to the end of the range. For example, after 10;+4print, cursor will be at line 14 wherever you run this command.
Q1: Is there a method to hold the cursor while executing this?
In addition, consider a user defined command with range, such as
command -range Test call TestFunc(<line1>, <line2>)
function TestFunc(line1, line2)
echo line('.')
endfunction
with line number shown.
Q2. run :10;+4Test will have cursor stop at line 10 and the result will has is also 10. This means the function is called after setting the cursor to line 10. The current line where the command is executed is not accessible (at least using line('.')). How should I get the correct line number in the function?
winsaveview()andwinrestview()– muru Aug 07 '17 at 07:4910) – doraemon Aug 07 '17 at 10:00