There are typically two ways to pass a range to a Normal-mode command.
One is to use a Visual selection (which is not exactly a Normal-mode command, but a Visual-mode one, but still pretty close) and the other is to create a mapping that takes an operator and acts on the range resulting of the operator or motions that follows it.
For the Visual-mode command, you get the
'> marks set to the beginning and end of the Visual selection, so you can simply call your user command with:
But since Vim will add the range automatically when you press
: from Visual mode (which already shows up with
:'<,'>), you don't even need to add that into your mapping! All you need is:
xnoremap <leader>t :Test<CR>
To use this mapping on range from current line to line 81, you can use:
That's assuming backslash as your
V will start Visual mode,
81G move to line 81, extending the selection and finally
\t invoke the Visual-mode mapping.
For the second option, creating a mapping that expects an operator, you set the
'operatorfunc' option to a function that will act on the range, then issue the
g@ command, which waits for an operator and invokes the function with the
'] marks set.
In your case:
nnoremap <silent> <leader>t :set operatorfunc=TestOpfunc<CR>g@
You can then invoke it with:
81G is the motion taken as the operator to define the range where to act, in this case from the current line until line 81.
:help :map-operator or
:help g@ for more details and examples on how to use
g@ and define an operator function. The examples also show how to reuse the function for the counterpart Visual-mode mapping.