Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Using Vim in Terminal on Mac OS X, my Option+Left Arrow skips words as expected, but my Option+Right Arrow does nothing. How can I fix this?

share|improve this question
    
Ew, arrow keys. A major advantage of vi/vim over other editors is that your fingers seldom have to leave the main keyboard. You can use w and W to skip to the next word, b or B to skip to the beginning of the current word (or of the previous word, if your cursor is already on the first character of the current word) and e or E to move to the end of the current word (or the end of the next word, if you are already at the end of the current word). Once you learn the proper way of using vim, it pretty quickly becomes muscle memory & is faster than using the arrow keys. –  evilsoup Aug 22 '13 at 22:05
    
Any good universal list of Vim commands you have bookmarked? The majority of the ones that I've found only have certain commands, or are missing some commands. –  NobleUplift Aug 22 '13 at 22:08
    
Here is a good page with basic navigation stuff -- and that wiki is fairly good in general. I don't know of any exhaustive list of commands (when I want to do something I don't know, I google it, and failing that ask here). You can use :help quickref for some commonly-used ones (to follow a link in the vim help pages, position your cursor over it and press Ctrl+]). For tutorial on the basics, run vimtutor from the command-line (not from within vim itself). –  evilsoup Aug 22 '13 at 22:35
add comment

1 Answer

up vote 1 down vote accepted

I'm not really sure if you want to change the default behavior as this isn't going to work very well in other terminal applications.

Option+Left moves back a word because vim sees it as esc+b. (seems to be the default in Terminal). So if you are in insert mode you are popped out to normal mode and than b is executed which is move back a word. If you are in normal mode the escape does nothing and b moves you back a word.

Option+Right looks like it does nothing because vim sees it as esc+f. The f causes vim to wait for the next letter and if you entered something right after the f you would move forward to find that letter.

One way to change it is to go into Terminals preferences and change what Option+Right is mapped to. You can do this by going to Preferences -> Settings -> Select Current Profile -> Keyboard. At this point you can either edit "option cursor right" or add a new "option cursor right" (by clicking the plus this will overwrite the actual one). And set the mapping to \033w by typing esc+w. Then hit ok with the mouse. (Hitting enter will cause the enter key to be absorbed by the text box. You do not want that)

After this is done open a new tab and Option+Right will do what you want in vim but probably won't do what you want anywhere else. (it might though)

One other way is to change the mappings to Control+Left and Control+Right. Normally in vim these are mapped to B and W respectively. To do this follow the instruction I wrote for Is there any way to go word by word using `Ctrl + ->`

Although learning how to use vim with only the keyboard is probably better.

share|improve this answer
    
Thanks! I think I'll try your other instructions instead, but don't get me wrong because I love the verboseness of your answer. I now understand why vim behaves the way it does. –  NobleUplift Aug 23 '13 at 13:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.