Move by word in bash

7

3

In bash, you can move to the beginning of the line with CTRL+A, and the end with CTRL+E. How can I move forward and backward by word?

user180297

Posted 2010-05-27T20:41:54.800

Reputation:

1man bash and then read the docs in the READLINE section. – Kaleb Pederson – 2010-05-27T20:44:49.780

Another handy reference for bash keyboard shortcuts: https://en.wikipedia.org/wiki/Bash_(Unix_shell)#Keyboard_shortcuts

– Amanda – 2012-10-26T14:02:17.160

Answers

12

With emacs bindings:

Meta-B moves back a word and Meta-F moves forward a word.

Ctrl-B moved back a character and Ctrl-F moves forward a character.

So B vs F is backwards vs forward and Meta vs Ctrl is word vs character.

The exact mapping of Meta may vary between keyboards. Try holding down Alt while pressing the other key; if that doesn't work, press and release Esc and then press the other key.

R Samuel Klatchko

Posted 2010-05-27T20:41:54.800

Reputation: 416

3

use alt+b for backward and alt+f for forward movement by a word.

neo730

Posted 2010-05-27T20:41:54.800

Reputation: 31

1

Put in ~/.inputrc:

# Ctrl+Left/Right to move by whole words.
"\e[1;5C": forward-word
"\e[1;5D": backward-word
# Same with Shift pressed.
"\e[1;6C": forward-word
"\e[1;6D": backward-word

gavenkoa

Posted 2010-05-27T20:41:54.800

Reputation: 1 386