Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically go to next line in vim

Tags:

vim

One frustrating behavior in vim is that when i move my cursor right or left (respectively "l" or "h)" and i am at the end or the beginning of the line, my cursor doesn't move to first column of next line or last column of previous line.

Is there a way to change this behavior ?

like image 460
jney Avatar asked Apr 04 '10 09:04

jney


People also ask

How do I move text to the next line in Vim?

I know that pressing 'o' in normal or visual mode moves the cursor to a new line and switches the mode to insert.

How do you go to the next line in vi?

Moving to Start or End of LinePress ^ to move the cursor to the start of the current line. Press $ to move the cursor to the end of the current line.

What is enter in Vim?

Type i to switch into insert mode so that you can start editing the file. Enter or modify the text with your file. Once you're done, press the escape key Esc to get out of insert mode and back to command mode. Type :wq to save and exit your file.


1 Answers

You can use the whichwrap setting to make h and l wrap around the start and end of individual lines:

set whichwrap+=h,l 

However, Vim's documentation recommends against this, probably because it could have unexpected side effects (like breaking plugins, or changing how common key mappings work).

As an alternative, you can do what what Matti Virkkunen recommended:

set whichwrap+=<,>,[,] 

This leaves h and l with their default behavior, but allows the left and right arrow keys to wrap around lines. (This is what I do, and it works well.)

You might also want to take a look at the backspace setting, to control how Backspace, Delete, Control+W, and Control+U work in Insert mode. I set mine like this:

set backspace=indent,eol,start 

That allows me to backspace over pretty much everything.

For more info, see these topics in the Vim help:

:help 'whichwrap :help 'backspace 
like image 94
Bill Odom Avatar answered Sep 18 '22 05:09

Bill Odom