In vim, how do I make the left and right arrow keys change line?

25

7

In vim, my arrow keys work correctly, moving up, down, left, and right as expected, with one exception. At the beginning of a line, left arrow does nothing, instead of going to the last character of the previous line. At the end of a line, right arrow does nothing, instead of going to the first character of the next line.

Is there a setting I can change to get the behavior I expect?

nohat

Posted 2009-09-04T00:15:17.743

Reputation: 795

4I would think that most VIM users would recommend that you don't use the arrow keys. – user12612 – 2010-07-23T18:45:33.470

@user12612 why exactly? – luchonacho – 2017-09-30T19:08:39.097

@luchonacho I think the idea is that serious VIM users would hold that your fingers should not leave the home row of your keyboard in order navigate where you are in your text. – nohat – 2017-10-02T20:32:12.010

Answers

26

After some further Googling, I found the answer is to use the whichwrap option.

I added the following line to my .vimrc:

set whichwrap+=<,>,[,]

The < and > options turn on the desired setting for normal mode and [ and ] turn on the desired setting for insert mode.

nohat

Posted 2009-09-04T00:15:17.743

Reputation: 795

Right, there are other values for h and j. See :help 'whichwrap' or https://vimhelp.appspot.com/options.txt.html#%27whichwrap%27 . k and l don't really apply since we're talking about left/right behavior at the beginning/end of lines.

– Adam Monsen – 2017-07-28T14:34:12.600

This doesn't seem to affect the behavior of h j k l keys. – Sebastián Grignoli – 2011-09-06T17:51:01.490

1(Why this was not the default setting on my system is a mystery) – nohat – 2009-10-05T08:39:39.513

9

Add this to your .vimrc:

set whichwrap+=<,>,h,l,[,]

gpista

Posted 2009-09-04T00:15:17.743

Reputation: 91

0

This is default behavior - you can always use Home and End to jump to the start and finish of a line however.

salmonmoose

Posted 2009-09-04T00:15:17.743

Reputation: 1 675

5OP wants to change default behavior. Thats why (s)he asked here in the first place. – akira – 2011-02-09T08:08:46.867

0

You can work around this by using w and b which will wrap across lines.

hasen

Posted 2009-09-04T00:15:17.743

Reputation: 4 556

But b takes you the first character of the last word of the previous line. Is there really no way to make left-arrow move to the last character of the previous line when at the first character of a line? – nohat – 2009-09-04T00:27:48.337

Yeah I know, It's not a real solution. – hasen – 2009-09-04T00:44:21.320