Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move forward/backward number of characters past end of line in VIM

Tags:

vim

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.

like image 604
Tyler Durden Avatar asked Jun 26 '14 13:06

Tyler Durden


3 Answers

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.

like image 62
DavidEG Avatar answered Oct 21 '22 10:10

DavidEG


You can set virtualedit option:

:set ve=all

Virtual editing means that the cursor can be positioned where there is no actual character.

like image 45
kev Avatar answered Oct 21 '22 10:10

kev


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
like image 24
Ingo Karkat Avatar answered Oct 21 '22 11:10

Ingo Karkat