我正在尝试定义一个可以采用范围并将其传递给函数的命令。这是我认为我应该拥有的:
function! PrintGivenRange() range
echo "firstline ".a:firstline." lastline ".a:lastline
" Do some more things
endfunction
command! -range PassRange call PrintGivenRange()
但是,它不起作用,它似乎只通过了第一行。
例如
:1,5PassRange "outputs firstline 1 lastline 1
:1,5call PrintGivenRange() "outputs firstline 1 lastline 5
" if you select lines in visual mode, same thing for both
我已经阅读:help command-range
了,但仍然无法弄清楚这一点。我应该将前缀中的范围传递给call
? 我该如何解决?