How can I move forward/backward number of characters past end of line in VIM?
I known I can type, for example,
25l
and go forwards 25 characters, but this command will always stop at the end of a line. Also, there is 25go
, but this goes forward from the beginning of the buffer, not forward from the current cursor position. I want to go forwards a certain number of characters including end of line characters.
I think what you are looking for is space to move forwards and backspace to move backwards.
space will continue in the following line. If you want to add spaces in the current line instead of moving to the next one then the :set virtualedit=onemore
is the option for you.
You can set virtualedit
option:
:set ve=all
Virtual editing means that the cursor can be positioned where there is no actual character.
The 'whichwrap'
option determines what motions can move the cursor to another line. By default, none of the left / right movements do that.
The inclusion of h,l
is not recommended, as some macros and plugins may depend on the original behavior and break - your call to test and decide. But it should be safe to include the ← and → cursor keys via (the latter pair is for insert mode and optional)
:set whichwrap+=<,>,[,]
Then, you can move by 5 characters across the line ending via 5 →.
Whether the newline character is counted or not depends on the 'virtualedit'
option. To include the newline:
:set virtualedit=onemore
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With