martanne / vis

A vi-like editor based on Plan 9's structural regular expressions
Other
4.21k stars 258 forks source link

Mapping a number prevents it from being use as count #901

Open silasdb opened 3 years ago

silasdb commented 3 years ago

You can use "count" parameters to many commands, like:

13dd -> delete next 13 lines

But digits get useless after you've remapped them to something else, even if they are not the first number. Try:

:map! normal 3

Now try to pass a count to a parameter that uses digit "3". E.g.: Go to 23th line: 23G . It fails.

I noticed this after trying to reverse "^" and "0".

ninewise commented 3 years ago

Well that does make sense? When :map! normal 3 j, 23j means move down twice, move down. I think 0 is a special case here because you're never start a count with 0. I'm not sure we'd want to add more special cases in case someone maps these numbers.

silasdb commented 3 years ago

Indeed, "0" is the important case here. Maybe it makes more sense to just implement a generic solution for any digit than for zero only, but I'm not familiar to the code to claim that.

ghost commented 3 years ago

Maybe it makes more sense to just implement a generic solution for any digit @silasdb

A "count-pending" mode, perhaps? A digit in normal/visual mode would switch to count-pending mode, which would only accept digits, and would go back to normal/visual (or switch to operator-pending) mode on the first non-digit key press.

A digit that was remapped would not cause a switch to count-pending mode, because the code that makes the switch won't see it as a digit. Then 0 could be "implemented" via such a mapping, without being a special case in the lower levels of the code.

Easier said than done, though.

martanne commented 3 years ago

I agree that a sub mode is the right way to properly fix this. There are however a few peculiarities to consider:

I hacked up a quick prototype how such a count sub mode could work with minimal changes. As you can see it still contains a few ugly corner cases.