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.

7 comments:

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

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

    ReplyDelete
  3. 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

    http://linuxart.com/log/archives/2005/10/13/super-useful-inputrc/

    ReplyDelete
  4. 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.

    ReplyDelete
  5. set -o vi
    use vi on the command line

    ReplyDelete
  6. hi,
    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.

    hanes

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

    ReplyDelete