I have a mapping that looks like this:
nnoremap <expr> <c-x>b ":call MyFunction(" . v:count . ")\<cr>"
I also tried to instead define function with range
, but the effect is the same.
The point is to be able to press a number, followed by the mapping, e.g. 30<c-x>b
. The problem is, it fails if the number of remaining lines in the file is less than count I input. The function actually don't do any line operations, so I don't care about actual number of lines. How can I make a mapping or a function that accepts count and isn't dependent on number of lines in open file?
Edit:
Here's my final version, with working solution:
nnoremap <expr> <c-x>b ":\<c-u>call MyFunction(" . (v:count ? v:count . ")\<cr>" : ")\<left>")
With this, if I press <number><c-b>x
, the function is called immediately, or if I press just <c-b>x
, I go into command prompt and can enter number manually (using v:count1
by default isn't suitable for my case).
v:count
in MyFunction, and not go through the expr hoops?range
makes more sense. It's just, as I stated in my question, I initially tried both approaches to see which one work. Now, with the solution, I'll revert back torange
.range
attribute is required to seev:count
in function scope, but apparently it's not, and I can accessv:count
right away.