8
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?
8
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?
6
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.
1Thanks! 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 – 2013-08-23T13:50:51.230
0
As of OS X Mojave 10.14.5, there is a much simpler solution:
You actually don't need to change anything in mac preferences. After a lot of experimentation it appears that all you need to do is put :map f w
in your .vimrc file!
For some reason specifying the escapes is unnecessary and actually interfered with expected behaviour for me. Doing what I suggested will automatically escape and do a forward-word on an alt+Right key entry (and of course the opposite currently does work automatically).
I just looked at the Vim Tips Wiki for perhaps the first time, and, based on a very quick review, I’m not impressed. (1) It doesn’t really explain what a “word” is (as opposed to a “WORD”). (2) It doesn’t mention
– Scott – 2019-06-27T04:13:55.303f
,F
,t
,T
,,
and;
. (3) It tediously describesw
,3w
,b
,3b
,j
,10j
, etc., without ever making a general statement that most of the commands can take a numeric argument (prefix). (4) Its explanation of the0
command doesn’t clearly emphasize how it is different from^
. … (Cont’d)(Cont’d) … (5) It lists
0
and|
about three pages apart, using different words, and doesn’t mention that they are synonymous. (6) It doesn’t mention+
and-
. (7) It doesn’t explainj
andk
well enough that you’d be able to tell that they are different from+
and-
. (8) It mentionsmx
,'x
and\
xwithout explaining that there are 26(ish) mark registers. (9) It doesn’t mention
/,
?,
nand
N. (10) It doesn’t explain what a “sentence” and a “paragraph” are. (11) It doesn’t mention that
Hand
L` take (numeric) arguments. (12) It doesn’t mention Ctrl+U and Ctrl+D. – Scott – 2019-06-27T04:13:57.827Ew, 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 – 2013-08-22T22:05:30.570
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 – 2013-08-22T22:08:04.327
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 pressCtrl
+]
). For tutorial on the basics, runvimtutor
from the command-line (not from within vim itself). – evilsoup – 2013-08-22T22:35:40.320