Sunday, February 17, 2008

Go to next/previous word on the command line

I have been looking for a way to move forward and backward on the command line by bigger chunks than just character by character. Something like go back a word, or go to next word.

I finally found it:

  • to go back a word, press Esc, then the letter b
  • to go forward a word, press Esc, then the letter f

I must say that the key sequence is some what awkward to hit right. Never mind about repeating it to move back/forward several words.

With that said, I found what I was looking for.


xnu!l said...

Alt+b and Alt+f seems much more convenient to me.

Chick said...

Map capslock to esc. Should't ppl do that for vi/emacs anyway?

underground unknown said...

you can map any key combination for forward-word and backward-word. Just try these in your ~/.inputrc:

"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word

Robert said...

Alt B and Alt F has the advantage of repeating the action by holding down alt, and repeatedly hitting f or b. Escape you have to release/depress again before you can repeat.

Anonymous said...

set -o vi
use vi on the command line

Anonymous said...

I don't get the problem; maybe it's because this article is five years old.
but I just hit Ctrl. and right/left arrow and Ctrl.+a to go to the beginning or Ctrl.+e to the end of the line.


karmakaze said...

With iTerm2, go to Preferences, Profiles, Keys and set Left option/Right option key acts as "+Esc"