[macos] How to move the cursor word by word in the OS X Terminal

I know the combination Ctrl+A to jump to the beginning of the current command, and Ctrl+E to jump to the end.

But is there any way to jump word by word, like Alt+/ in Cocoa applications does?

This question is related to macos terminal keyboard-shortcuts

The answer is


Out of the box you can use the quite bizarre Esc+F to move to the beginning of the next word and Esc+B to move to the beginning of the current word.


In Bash, these are bound to Esc-B and Esc-F. Bash has many, many more keyboard shortcuts; have a look at the output of bind -p to see what they are.


Actually it depends on what shell you use, however most shells have similar bindings. The bindings you are referring to (e.g. Ctrl+A and Ctrl+E) are bindings you will find in many other programs and they are used for ages, BTW also work in most UI apps.

Here's a look of default bindings for Bash:

Most Important Bash Keyboard Shortcuts

Please also note that you can customize them. You need to create a file, name as you wish, I named mine .bash_key_bindings and put it into my home directory. There you can set some general bash options and you can also set key bindings. To make sure they are applied, you need to modify a file named ".bashrc" that bash reads in upon start-up (you must create it, if it does not exist) and make the following call there:

bind -f ~/.bash_key_bindings

~ means home directory in bash, as stated above, you can name the file as you like and also place it where you like as long as you feed the right path+name to bind.

Let me show you some excerpts of my .bash_key_bindings file:

set meta-flag on
set input-meta on
set output-meta on
set convert-meta off
set show-all-if-ambiguous on
set bell-style none
set print-completions-horizontally off

These just set a couple of options (e.g. disable the bell; this can be all looked up on the bash webpage).

"A": self-insert
"B": self-insert
"C": self-insert
"D": self-insert
"E": self-insert
"F": self-insert
"G": self-insert
"H": self-insert
"I": self-insert
"J": self-insert

These make sure that the characters alone just do nothing but making sure the character is "typed" (they insert themselves on the shell).

"\C-dW": kill-word
"\C-dL": kill-line
"\C-dw": backward-kill-word
"\C-dl": backward-kill-line
"\C-da": kill-line

This is quite interesting. If I hit Ctrl+D alone (I selected d for delete), nothing happens. But if I then type a lower case w, the word to the left of the cursor is deleted. If I type an upper case, however, the word to the right of the cursor is killed. Same goes for l and L regarding the whole line starting from the cursor. If I type an "a", the whole line is actually deleted (everything before and after the cursor).

I placed jumping one word forward on Ctrl+F and one word backward on Ctrl+B

"\C-f": forward-word
"\C-b": backward-word

As you can see, you can make a shortcut, that leads to an action immediately, or you can make one, that just inits a character sequence and then you have to type one (or more) characters to cause an action to take place as shown in the example further above.

So if you are not happy with the default bindings, feel free to customize them as you like. Here's a link to the bash manual for more information.


New answer for iTerm2 Build 3.3.4 users:

Step 1: (macOS X) System Preferences > Keyboard > Shortcuts tab > Select Mission Control (left panel) > Uncheck shortcuts that labeled as "Move left a space" and "Move right a space"

Step 2: (iTerm2 Build 3.3.4) Preferences > Profiles > Select * Default (left panel) > Keys tab > Delete both "?->" and "?<-" entries > Set both "Left Option (?) Key:" and "Right Option (?) Key:" to Esc+

No messing around with shell profiles, no messing around with inferior masOS (default) Terminal, no awkwards Esc+F/B, rinse & repeat non-sense.

Done deal!!!

Enjoy this tip, my fellow PROGRAMMERS!


Switch to iTerm2. It's free and much nicer than plain old terminal. Also it has a lot more options for customization, like keyboard shortcuts.

Also I love that you can use cmd and 1-9 to switch between tabs. Try it and you will never go back to regular terminal :)

How to set up custom keyboard preferences in iterm2

  • Install iTerm2
  • Launch and then go to preference pane.
  • Choose the keyboard profiles tab
  • You will either need to copy the profile to something new and then delete the arrow key shortcuts such as ^+ Right/Left or if you don't care about a backup just delete them from the default profile.
  • Next make sure your modified profile is selected (starred)

Picture 1.png

  • Now choose the keyboard tab (very top row)

iTerm 2

  • Click on the plus button to add a new keyboard shortcut
  • In the first box type CMD+Left arrow
  • In the second box choose "send escape code"
  • In the third box type the letter B

Picture 2.png

  • Repeat with desired key combinations. escape+B moves one word to the left, escape+f moves one word to the right.
  • you may also wish to set up cmd+d to delete the word in front of the cursor with escape+d

I often hit the wrong button (cmd / control / alt) with an arrow key and so i have my arrow key combinations with those buttons all set to jump forward and back words, but please do what fits you best.


If you happen to be a Vim user, you could try bash's vim mode. Run this or put it in your ~/.bashrc file:

set -o vi

By default you're in insert mode; hit escape and you can move around just like you can in normal-mode Vim, so movement by word is w or b, and the usual movement keys also work.


In Bash, these are bound to Esc-B and Esc-F. Bash has many, many more keyboard shortcuts; have a look at the output of bind -p to see what they are.


As answered previously, you can add set -o vi in your ~/.bashrc to use vi/vim key bindings, or else you can add following part in .bashrc to move with Ctrl and arrow keys:

# bindings to move 1 word left/right with ctrl+left/right in terminal, just some apple stuff!
bind '"\e[5C": forward-word'
bind '"\e[5D": backward-word'
# bindings to move 1 word left/right with ctrl+left/right in iTerm2, just some apple stuff!
bind '"\e[1;5C": forward-word'
bind '"\e[1;5D": backward-word'

To start effect of these lines of code, either source ~/.bashrc or start a new terminal session.


As of Mac OS X Lion 10.7, Terminal maps Option-Left/Right Arrow to Esc-b/f by default, so this is now built-in for bash and other programs that use these emacs-compatible keybindings.


Here's how you can do it

By default, the Terminal has these shortcuts to move (left and right) word-by-word:

  • esc+B (left)
  • esc+F (right)

You can configure alt+ and to generate those sequences for you:

  • Open Terminal preferences (cmd+,);
  • At Settings tab, select Keyboard and double-click ? ? if it's there, or add it if it's not.
  • Set the modifier as desired, and type the shortcut key in the box: esc+B, generating the text \033b (you can't type this text manually).
  • Repeat for word-right (esc+F becomes \033f)

Alternatively, you can refer to this blog post over at textmate:

http://blog.macromates.com/2006/word-movement-in-terminal/


Use Natural Text Editing preset!

enter image description here

Essentially it binds, among other key sequences, Option + LeftArrow to ^[b sequence and Option + RightArrow to ^[f

This works in fish and bash, as well as in psql terminal.


New answer for iTerm2 Build 3.3.4 users:

Step 1: (macOS X) System Preferences > Keyboard > Shortcuts tab > Select Mission Control (left panel) > Uncheck shortcuts that labeled as "Move left a space" and "Move right a space"

Step 2: (iTerm2 Build 3.3.4) Preferences > Profiles > Select * Default (left panel) > Keys tab > Delete both "?->" and "?<-" entries > Set both "Left Option (?) Key:" and "Right Option (?) Key:" to Esc+

No messing around with shell profiles, no messing around with inferior masOS (default) Terminal, no awkwards Esc+F/B, rinse & repeat non-sense.

Done deal!!!

Enjoy this tip, my fellow PROGRAMMERS!


Under iterm2's Preferences > Profile > Keys, you click the + below Key Mappings and record a new shortcut. For Action, select Send Escape Sequence and type b or f for backwards and forwards respectively.

When I tried to record one for (Ctrl+?), I noticed in the Keyboard Shortcut field that the arrow never showed up. Turns out I had to disable the default mac's System Preferences > Keyboard > Shortcuts > Mission Control shorcuts first to get things to work, as they'll override iterm2's default shortcuts. Should be true for the standard terminal app, too.

Keyboard system preferences


Actually it depends on what shell you use, however most shells have similar bindings. The bindings you are referring to (e.g. Ctrl+A and Ctrl+E) are bindings you will find in many other programs and they are used for ages, BTW also work in most UI apps.

Here's a look of default bindings for Bash:

Most Important Bash Keyboard Shortcuts

Please also note that you can customize them. You need to create a file, name as you wish, I named mine .bash_key_bindings and put it into my home directory. There you can set some general bash options and you can also set key bindings. To make sure they are applied, you need to modify a file named ".bashrc" that bash reads in upon start-up (you must create it, if it does not exist) and make the following call there:

bind -f ~/.bash_key_bindings

~ means home directory in bash, as stated above, you can name the file as you like and also place it where you like as long as you feed the right path+name to bind.

Let me show you some excerpts of my .bash_key_bindings file:

set meta-flag on
set input-meta on
set output-meta on
set convert-meta off
set show-all-if-ambiguous on
set bell-style none
set print-completions-horizontally off

These just set a couple of options (e.g. disable the bell; this can be all looked up on the bash webpage).

"A": self-insert
"B": self-insert
"C": self-insert
"D": self-insert
"E": self-insert
"F": self-insert
"G": self-insert
"H": self-insert
"I": self-insert
"J": self-insert

These make sure that the characters alone just do nothing but making sure the character is "typed" (they insert themselves on the shell).

"\C-dW": kill-word
"\C-dL": kill-line
"\C-dw": backward-kill-word
"\C-dl": backward-kill-line
"\C-da": kill-line

This is quite interesting. If I hit Ctrl+D alone (I selected d for delete), nothing happens. But if I then type a lower case w, the word to the left of the cursor is deleted. If I type an upper case, however, the word to the right of the cursor is killed. Same goes for l and L regarding the whole line starting from the cursor. If I type an "a", the whole line is actually deleted (everything before and after the cursor).

I placed jumping one word forward on Ctrl+F and one word backward on Ctrl+B

"\C-f": forward-word
"\C-b": backward-word

As you can see, you can make a shortcut, that leads to an action immediately, or you can make one, that just inits a character sequence and then you have to type one (or more) characters to cause an action to take place as shown in the example further above.

So if you are not happy with the default bindings, feel free to customize them as you like. Here's a link to the bash manual for more information.


In Bash, these are bound to Esc-B and Esc-F. Bash has many, many more keyboard shortcuts; have a look at the output of bind -p to see what they are.


New answer for iTerm2 Build 3.3.4 users:

Step 1: (macOS X) System Preferences > Keyboard > Shortcuts tab > Select Mission Control (left panel) > Uncheck shortcuts that labeled as "Move left a space" and "Move right a space"

Step 2: (iTerm2 Build 3.3.4) Preferences > Profiles > Select * Default (left panel) > Keys tab > Delete both "?->" and "?<-" entries > Set both "Left Option (?) Key:" and "Right Option (?) Key:" to Esc+

No messing around with shell profiles, no messing around with inferior masOS (default) Terminal, no awkwards Esc+F/B, rinse & repeat non-sense.

Done deal!!!

Enjoy this tip, my fellow PROGRAMMERS!


For some reason, my terminal's option+arrow weren't working. To fix this on macOS 10.15.6, I opened the terminal app's preferences, and had to set the bindings.

Option-left = \033b
Option-right = \033e

Keyboard settings in Mac terminal app

For some reason, the option-right I had was set up to be \033f. Now that it's fixed, I can freely skip around words in the termianl again.


As of Mac OS X Lion 10.7, Terminal maps Option-Left/Right Arrow to Esc-b/f by default, so this is now built-in for bash and other programs that use these emacs-compatible keybindings.


Switch to iTerm2. It's free and much nicer than plain old terminal. Also it has a lot more options for customization, like keyboard shortcuts.

Also I love that you can use cmd and 1-9 to switch between tabs. Try it and you will never go back to regular terminal :)

How to set up custom keyboard preferences in iterm2

  • Install iTerm2
  • Launch and then go to preference pane.
  • Choose the keyboard profiles tab
  • You will either need to copy the profile to something new and then delete the arrow key shortcuts such as ^+ Right/Left or if you don't care about a backup just delete them from the default profile.
  • Next make sure your modified profile is selected (starred)

Picture 1.png

  • Now choose the keyboard tab (very top row)

iTerm 2

  • Click on the plus button to add a new keyboard shortcut
  • In the first box type CMD+Left arrow
  • In the second box choose "send escape code"
  • In the third box type the letter B

Picture 2.png

  • Repeat with desired key combinations. escape+B moves one word to the left, escape+f moves one word to the right.
  • you may also wish to set up cmd+d to delete the word in front of the cursor with escape+d

I often hit the wrong button (cmd / control / alt) with an arrow key and so i have my arrow key combinations with those buttons all set to jump forward and back words, but please do what fits you best.


Use Natural Text Editing preset!

enter image description here

Essentially it binds, among other key sequences, Option + LeftArrow to ^[b sequence and Option + RightArrow to ^[f

This works in fish and bash, as well as in psql terminal.


New answer for iTerm2 Build 3.3.4 users:

Step 1: (macOS X) System Preferences > Keyboard > Shortcuts tab > Select Mission Control (left panel) > Uncheck shortcuts that labeled as "Move left a space" and "Move right a space"

Step 2: (iTerm2 Build 3.3.4) Preferences > Profiles > Select * Default (left panel) > Keys tab > Delete both "?->" and "?<-" entries > Set both "Left Option (?) Key:" and "Right Option (?) Key:" to Esc+

No messing around with shell profiles, no messing around with inferior masOS (default) Terminal, no awkwards Esc+F/B, rinse & repeat non-sense.

Done deal!!!

Enjoy this tip, my fellow PROGRAMMERS!


I have Alt+/ working: open Preferences » Settings » Keyboard, set the entry for option cursor left to send string to shell: \033b, and set option cursor right to send string to shell: \033f. You can also use this for other Control key combinations.


In Bash, these are bound to Esc-B and Esc-F. Bash has many, many more keyboard shortcuts; have a look at the output of bind -p to see what they are.


Actually it depends on what shell you use, however most shells have similar bindings. The bindings you are referring to (e.g. Ctrl+A and Ctrl+E) are bindings you will find in many other programs and they are used for ages, BTW also work in most UI apps.

Here's a look of default bindings for Bash:

Most Important Bash Keyboard Shortcuts

Please also note that you can customize them. You need to create a file, name as you wish, I named mine .bash_key_bindings and put it into my home directory. There you can set some general bash options and you can also set key bindings. To make sure they are applied, you need to modify a file named ".bashrc" that bash reads in upon start-up (you must create it, if it does not exist) and make the following call there:

bind -f ~/.bash_key_bindings

~ means home directory in bash, as stated above, you can name the file as you like and also place it where you like as long as you feed the right path+name to bind.

Let me show you some excerpts of my .bash_key_bindings file:

set meta-flag on
set input-meta on
set output-meta on
set convert-meta off
set show-all-if-ambiguous on
set bell-style none
set print-completions-horizontally off

These just set a couple of options (e.g. disable the bell; this can be all looked up on the bash webpage).

"A": self-insert
"B": self-insert
"C": self-insert
"D": self-insert
"E": self-insert
"F": self-insert
"G": self-insert
"H": self-insert
"I": self-insert
"J": self-insert

These make sure that the characters alone just do nothing but making sure the character is "typed" (they insert themselves on the shell).

"\C-dW": kill-word
"\C-dL": kill-line
"\C-dw": backward-kill-word
"\C-dl": backward-kill-line
"\C-da": kill-line

This is quite interesting. If I hit Ctrl+D alone (I selected d for delete), nothing happens. But if I then type a lower case w, the word to the left of the cursor is deleted. If I type an upper case, however, the word to the right of the cursor is killed. Same goes for l and L regarding the whole line starting from the cursor. If I type an "a", the whole line is actually deleted (everything before and after the cursor).

I placed jumping one word forward on Ctrl+F and one word backward on Ctrl+B

"\C-f": forward-word
"\C-b": backward-word

As you can see, you can make a shortcut, that leads to an action immediately, or you can make one, that just inits a character sequence and then you have to type one (or more) characters to cause an action to take place as shown in the example further above.

So if you are not happy with the default bindings, feel free to customize them as you like. Here's a link to the bash manual for more information.


As answered previously, you can add set -o vi in your ~/.bashrc to use vi/vim key bindings, or else you can add following part in .bashrc to move with Ctrl and arrow keys:

# bindings to move 1 word left/right with ctrl+left/right in terminal, just some apple stuff!
bind '"\e[5C": forward-word'
bind '"\e[5D": backward-word'
# bindings to move 1 word left/right with ctrl+left/right in iTerm2, just some apple stuff!
bind '"\e[1;5C": forward-word'
bind '"\e[1;5D": backward-word'

To start effect of these lines of code, either source ~/.bashrc or start a new terminal session.


On Mac OS X - the following keyboard shortcuts work by default. Note that you have to make Option key act like Meta in Terminal preferences (under keyboard tab)

  • alt (?)+F to jump Forward by a word
  • alt (?)+B to jump Backward by a word

I have observed that default emacs key-bindings for simple text navigation seem to work on bash shells. You can use

  • alt (?)+D to delete a word starting from the current cursor position
  • ctrl+A to jump to start of the line
  • ctrl+E to jump to end of the line
  • ctrl+K to kill the line starting from the cursor position
  • ctrl+Y to paste text from the kill buffer
  • ctrl+R to reverse search for commands you typed in the past from your history
  • ctrl+S to forward search (works in zsh for me but not bash)
  • ctrl+F to move forward by a char
  • ctrl+B to move backward by a char
  • ctrl+W to remove the word backwards from cursor position

If you check Use option as meta key in the keyboard tab of the preferences, then the default emacs style commands for forward- and backward-word and ?F (Alt+F) and ?B (Alt+B) respectively.

I'd recommend reading From Bash to Z-Shell. If you want to increase your bash/zsh prowess!


For some reason, my terminal's option+arrow weren't working. To fix this on macOS 10.15.6, I opened the terminal app's preferences, and had to set the bindings.

Option-left = \033b
Option-right = \033e

Keyboard settings in Mac terminal app

For some reason, the option-right I had was set up to be \033f. Now that it's fixed, I can freely skip around words in the termianl again.


On Mac OS X - the following keyboard shortcuts work by default. Note that you have to make Option key act like Meta in Terminal preferences (under keyboard tab)

  • alt (?)+F to jump Forward by a word
  • alt (?)+B to jump Backward by a word

I have observed that default emacs key-bindings for simple text navigation seem to work on bash shells. You can use

  • alt (?)+D to delete a word starting from the current cursor position
  • ctrl+A to jump to start of the line
  • ctrl+E to jump to end of the line
  • ctrl+K to kill the line starting from the cursor position
  • ctrl+Y to paste text from the kill buffer
  • ctrl+R to reverse search for commands you typed in the past from your history
  • ctrl+S to forward search (works in zsh for me but not bash)
  • ctrl+F to move forward by a char
  • ctrl+B to move backward by a char
  • ctrl+W to remove the word backwards from cursor position

I have Alt+/ working: open Preferences » Settings » Keyboard, set the entry for option cursor left to send string to shell: \033b, and set option cursor right to send string to shell: \033f. You can also use this for other Control key combinations.


Here's how you can do it

By default, the Terminal has these shortcuts to move (left and right) word-by-word:

  • esc+B (left)
  • esc+F (right)

You can configure alt+ and to generate those sequences for you:

  • Open Terminal preferences (cmd+,);
  • At Settings tab, select Keyboard and double-click ? ? if it's there, or add it if it's not.
  • Set the modifier as desired, and type the shortcut key in the box: esc+B, generating the text \033b (you can't type this text manually).
  • Repeat for word-right (esc+F becomes \033f)

Alternatively, you can refer to this blog post over at textmate:

http://blog.macromates.com/2006/word-movement-in-terminal/


Switch to iTerm2. It's free and much nicer than plain old terminal. Also it has a lot more options for customization, like keyboard shortcuts.

Also I love that you can use cmd and 1-9 to switch between tabs. Try it and you will never go back to regular terminal :)

How to set up custom keyboard preferences in iterm2

  • Install iTerm2
  • Launch and then go to preference pane.
  • Choose the keyboard profiles tab
  • You will either need to copy the profile to something new and then delete the arrow key shortcuts such as ^+ Right/Left or if you don't care about a backup just delete them from the default profile.
  • Next make sure your modified profile is selected (starred)

Picture 1.png

  • Now choose the keyboard tab (very top row)

iTerm 2

  • Click on the plus button to add a new keyboard shortcut
  • In the first box type CMD+Left arrow
  • In the second box choose "send escape code"
  • In the third box type the letter B

Picture 2.png

  • Repeat with desired key combinations. escape+B moves one word to the left, escape+f moves one word to the right.
  • you may also wish to set up cmd+d to delete the word in front of the cursor with escape+d

I often hit the wrong button (cmd / control / alt) with an arrow key and so i have my arrow key combinations with those buttons all set to jump forward and back words, but please do what fits you best.


Actually it depends on what shell you use, however most shells have similar bindings. The bindings you are referring to (e.g. Ctrl+A and Ctrl+E) are bindings you will find in many other programs and they are used for ages, BTW also work in most UI apps.

Here's a look of default bindings for Bash:

Most Important Bash Keyboard Shortcuts

Please also note that you can customize them. You need to create a file, name as you wish, I named mine .bash_key_bindings and put it into my home directory. There you can set some general bash options and you can also set key bindings. To make sure they are applied, you need to modify a file named ".bashrc" that bash reads in upon start-up (you must create it, if it does not exist) and make the following call there:

bind -f ~/.bash_key_bindings

~ means home directory in bash, as stated above, you can name the file as you like and also place it where you like as long as you feed the right path+name to bind.

Let me show you some excerpts of my .bash_key_bindings file:

set meta-flag on
set input-meta on
set output-meta on
set convert-meta off
set show-all-if-ambiguous on
set bell-style none
set print-completions-horizontally off

These just set a couple of options (e.g. disable the bell; this can be all looked up on the bash webpage).

"A": self-insert
"B": self-insert
"C": self-insert
"D": self-insert
"E": self-insert
"F": self-insert
"G": self-insert
"H": self-insert
"I": self-insert
"J": self-insert

These make sure that the characters alone just do nothing but making sure the character is "typed" (they insert themselves on the shell).

"\C-dW": kill-word
"\C-dL": kill-line
"\C-dw": backward-kill-word
"\C-dl": backward-kill-line
"\C-da": kill-line

This is quite interesting. If I hit Ctrl+D alone (I selected d for delete), nothing happens. But if I then type a lower case w, the word to the left of the cursor is deleted. If I type an upper case, however, the word to the right of the cursor is killed. Same goes for l and L regarding the whole line starting from the cursor. If I type an "a", the whole line is actually deleted (everything before and after the cursor).

I placed jumping one word forward on Ctrl+F and one word backward on Ctrl+B

"\C-f": forward-word
"\C-b": backward-word

As you can see, you can make a shortcut, that leads to an action immediately, or you can make one, that just inits a character sequence and then you have to type one (or more) characters to cause an action to take place as shown in the example further above.

So if you are not happy with the default bindings, feel free to customize them as you like. Here's a link to the bash manual for more information.


If you check Use option as meta key in the keyboard tab of the preferences, then the default emacs style commands for forward- and backward-word and ?F (Alt+F) and ?B (Alt+B) respectively.

I'd recommend reading From Bash to Z-Shell. If you want to increase your bash/zsh prowess!


I have Alt+/ working: open Preferences » Settings » Keyboard, set the entry for option cursor left to send string to shell: \033b, and set option cursor right to send string to shell: \033f. You can also use this for other Control key combinations.


If you check Use option as meta key in the keyboard tab of the preferences, then the default emacs style commands for forward- and backward-word and ?F (Alt+F) and ?B (Alt+B) respectively.

I'd recommend reading From Bash to Z-Shell. If you want to increase your bash/zsh prowess!


Actually it depends on what shell you use, however most shells have similar bindings. The bindings you are referring to (e.g. Ctrl+A and Ctrl+E) are bindings you will find in many other programs and they are used for ages, BTW also work in most UI apps.

Here's a look of default bindings for Bash:

Most Important Bash Keyboard Shortcuts

Please also note that you can customize them. You need to create a file, name as you wish, I named mine .bash_key_bindings and put it into my home directory. There you can set some general bash options and you can also set key bindings. To make sure they are applied, you need to modify a file named ".bashrc" that bash reads in upon start-up (you must create it, if it does not exist) and make the following call there:

bind -f ~/.bash_key_bindings

~ means home directory in bash, as stated above, you can name the file as you like and also place it where you like as long as you feed the right path+name to bind.

Let me show you some excerpts of my .bash_key_bindings file:

set meta-flag on
set input-meta on
set output-meta on
set convert-meta off
set show-all-if-ambiguous on
set bell-style none
set print-completions-horizontally off

These just set a couple of options (e.g. disable the bell; this can be all looked up on the bash webpage).

"A": self-insert
"B": self-insert
"C": self-insert
"D": self-insert
"E": self-insert
"F": self-insert
"G": self-insert
"H": self-insert
"I": self-insert
"J": self-insert

These make sure that the characters alone just do nothing but making sure the character is "typed" (they insert themselves on the shell).

"\C-dW": kill-word
"\C-dL": kill-line
"\C-dw": backward-kill-word
"\C-dl": backward-kill-line
"\C-da": kill-line

This is quite interesting. If I hit Ctrl+D alone (I selected d for delete), nothing happens. But if I then type a lower case w, the word to the left of the cursor is deleted. If I type an upper case, however, the word to the right of the cursor is killed. Same goes for l and L regarding the whole line starting from the cursor. If I type an "a", the whole line is actually deleted (everything before and after the cursor).

I placed jumping one word forward on Ctrl+F and one word backward on Ctrl+B

"\C-f": forward-word
"\C-b": backward-word

As you can see, you can make a shortcut, that leads to an action immediately, or you can make one, that just inits a character sequence and then you have to type one (or more) characters to cause an action to take place as shown in the example further above.

So if you are not happy with the default bindings, feel free to customize them as you like. Here's a link to the bash manual for more information.


If you happen to be a Vim user, you could try bash's vim mode. Run this or put it in your ~/.bashrc file:

set -o vi

By default you're in insert mode; hit escape and you can move around just like you can in normal-mode Vim, so movement by word is w or b, and the usual movement keys also work.


Here's how you can do it

By default, the Terminal has these shortcuts to move (left and right) word-by-word:

  • esc+B (left)
  • esc+F (right)

You can configure alt+ and to generate those sequences for you:

  • Open Terminal preferences (cmd+,);
  • At Settings tab, select Keyboard and double-click ? ? if it's there, or add it if it's not.
  • Set the modifier as desired, and type the shortcut key in the box: esc+B, generating the text \033b (you can't type this text manually).
  • Repeat for word-right (esc+F becomes \033f)

Alternatively, you can refer to this blog post over at textmate:

http://blog.macromates.com/2006/word-movement-in-terminal/


In Bash, these are bound to Esc-B and Esc-F. Bash has many, many more keyboard shortcuts; have a look at the output of bind -p to see what they are.


If you happen to be a Vim user, you could try bash's vim mode. Run this or put it in your ~/.bashrc file:

set -o vi

By default you're in insert mode; hit escape and you can move around just like you can in normal-mode Vim, so movement by word is w or b, and the usual movement keys also work.


Switch to iTerm2. It's free and much nicer than plain old terminal. Also it has a lot more options for customization, like keyboard shortcuts.

Also I love that you can use cmd and 1-9 to switch between tabs. Try it and you will never go back to regular terminal :)

How to set up custom keyboard preferences in iterm2

  • Install iTerm2
  • Launch and then go to preference pane.
  • Choose the keyboard profiles tab
  • You will either need to copy the profile to something new and then delete the arrow key shortcuts such as ^+ Right/Left or if you don't care about a backup just delete them from the default profile.
  • Next make sure your modified profile is selected (starred)

Picture 1.png

  • Now choose the keyboard tab (very top row)

iTerm 2

  • Click on the plus button to add a new keyboard shortcut
  • In the first box type CMD+Left arrow
  • In the second box choose "send escape code"
  • In the third box type the letter B

Picture 2.png

  • Repeat with desired key combinations. escape+B moves one word to the left, escape+f moves one word to the right.
  • you may also wish to set up cmd+d to delete the word in front of the cursor with escape+d

I often hit the wrong button (cmd / control / alt) with an arrow key and so i have my arrow key combinations with those buttons all set to jump forward and back words, but please do what fits you best.


I have Alt+/ working: open Preferences » Settings » Keyboard, set the entry for option cursor left to send string to shell: \033b, and set option cursor right to send string to shell: \033f. You can also use this for other Control key combinations.


As of Mac OS X Lion 10.7, Terminal maps Option-Left/Right Arrow to Esc-b/f by default, so this is now built-in for bash and other programs that use these emacs-compatible keybindings.


In Bash, these are bound to Esc-B and Esc-F. Bash has many, many more keyboard shortcuts; have a look at the output of bind -p to see what they are.


I have Alt+/ working: open Preferences » Settings » Keyboard, set the entry for option cursor left to send string to shell: \033b, and set option cursor right to send string to shell: \033f. You can also use this for other Control key combinations.


As of Mac OS X Lion 10.7, Terminal maps Option-Left/Right Arrow to Esc-b/f by default, so this is now built-in for bash and other programs that use these emacs-compatible keybindings.


Hold down the Option key and click where you'd like the cursor to move


Actually there is a much better approach. Hold option ( alt on some keyboards) and press the arrow keys left or right to move by word. Simple as that.

option
option

Also ctrle will take you to the end of the line and ctrla will take you to the start.


Under iterm2's Preferences > Profile > Keys, you click the + below Key Mappings and record a new shortcut. For Action, select Send Escape Sequence and type b or f for backwards and forwards respectively.

When I tried to record one for (Ctrl+?), I noticed in the Keyboard Shortcut field that the arrow never showed up. Turns out I had to disable the default mac's System Preferences > Keyboard > Shortcuts > Mission Control shorcuts first to get things to work, as they'll override iterm2's default shortcuts. Should be true for the standard terminal app, too.

Keyboard system preferences


In Bash, these are bound to Esc-B and Esc-F. Bash has many, many more keyboard shortcuts; have a look at the output of bind -p to see what they are.


Use Natural Text Editing preset!

enter image description here

Essentially it binds, among other key sequences, Option + LeftArrow to ^[b sequence and Option + RightArrow to ^[f

This works in fish and bash, as well as in psql terminal.


As answered previously, you can add set -o vi in your ~/.bashrc to use vi/vim key bindings, or else you can add following part in .bashrc to move with Ctrl and arrow keys:

# bindings to move 1 word left/right with ctrl+left/right in terminal, just some apple stuff!
bind '"\e[5C": forward-word'
bind '"\e[5D": backward-word'
# bindings to move 1 word left/right with ctrl+left/right in iTerm2, just some apple stuff!
bind '"\e[1;5C": forward-word'
bind '"\e[1;5D": backward-word'

To start effect of these lines of code, either source ~/.bashrc or start a new terminal session.


On Mac OS X - the following keyboard shortcuts work by default. Note that you have to make Option key act like Meta in Terminal preferences (under keyboard tab)

  • alt (?)+F to jump Forward by a word
  • alt (?)+B to jump Backward by a word

I have observed that default emacs key-bindings for simple text navigation seem to work on bash shells. You can use

  • alt (?)+D to delete a word starting from the current cursor position
  • ctrl+A to jump to start of the line
  • ctrl+E to jump to end of the line
  • ctrl+K to kill the line starting from the cursor position
  • ctrl+Y to paste text from the kill buffer
  • ctrl+R to reverse search for commands you typed in the past from your history
  • ctrl+S to forward search (works in zsh for me but not bash)
  • ctrl+F to move forward by a char
  • ctrl+B to move backward by a char
  • ctrl+W to remove the word backwards from cursor position

Here's how you can do it

By default, the Terminal has these shortcuts to move (left and right) word-by-word:

  • esc+B (left)
  • esc+F (right)

You can configure alt+ and to generate those sequences for you:

  • Open Terminal preferences (cmd+,);
  • At Settings tab, select Keyboard and double-click ? ? if it's there, or add it if it's not.
  • Set the modifier as desired, and type the shortcut key in the box: esc+B, generating the text \033b (you can't type this text manually).
  • Repeat for word-right (esc+F becomes \033f)

Alternatively, you can refer to this blog post over at textmate:

http://blog.macromates.com/2006/word-movement-in-terminal/


If you check Use option as meta key in the keyboard tab of the preferences, then the default emacs style commands for forward- and backward-word and ?F (Alt+F) and ?B (Alt+B) respectively.

I'd recommend reading From Bash to Z-Shell. If you want to increase your bash/zsh prowess!


Hold down the Option key and click where you'd like the cursor to move


Here's how you can do it

By default, the Terminal has these shortcuts to move (left and right) word-by-word:

  • esc+B (left)
  • esc+F (right)

You can configure alt+ and to generate those sequences for you:

  • Open Terminal preferences (cmd+,);
  • At Settings tab, select Keyboard and double-click ? ? if it's there, or add it if it's not.
  • Set the modifier as desired, and type the shortcut key in the box: esc+B, generating the text \033b (you can't type this text manually).
  • Repeat for word-right (esc+F becomes \033f)

Alternatively, you can refer to this blog post over at textmate:

http://blog.macromates.com/2006/word-movement-in-terminal/


Actually it depends on what shell you use, however most shells have similar bindings. The bindings you are referring to (e.g. Ctrl+A and Ctrl+E) are bindings you will find in many other programs and they are used for ages, BTW also work in most UI apps.

Here's a look of default bindings for Bash:

Most Important Bash Keyboard Shortcuts

Please also note that you can customize them. You need to create a file, name as you wish, I named mine .bash_key_bindings and put it into my home directory. There you can set some general bash options and you can also set key bindings. To make sure they are applied, you need to modify a file named ".bashrc" that bash reads in upon start-up (you must create it, if it does not exist) and make the following call there:

bind -f ~/.bash_key_bindings

~ means home directory in bash, as stated above, you can name the file as you like and also place it where you like as long as you feed the right path+name to bind.

Let me show you some excerpts of my .bash_key_bindings file:

set meta-flag on
set input-meta on
set output-meta on
set convert-meta off
set show-all-if-ambiguous on
set bell-style none
set print-completions-horizontally off

These just set a couple of options (e.g. disable the bell; this can be all looked up on the bash webpage).

"A": self-insert
"B": self-insert
"C": self-insert
"D": self-insert
"E": self-insert
"F": self-insert
"G": self-insert
"H": self-insert
"I": self-insert
"J": self-insert

These make sure that the characters alone just do nothing but making sure the character is "typed" (they insert themselves on the shell).

"\C-dW": kill-word
"\C-dL": kill-line
"\C-dw": backward-kill-word
"\C-dl": backward-kill-line
"\C-da": kill-line

This is quite interesting. If I hit Ctrl+D alone (I selected d for delete), nothing happens. But if I then type a lower case w, the word to the left of the cursor is deleted. If I type an upper case, however, the word to the right of the cursor is killed. Same goes for l and L regarding the whole line starting from the cursor. If I type an "a", the whole line is actually deleted (everything before and after the cursor).

I placed jumping one word forward on Ctrl+F and one word backward on Ctrl+B

"\C-f": forward-word
"\C-b": backward-word

As you can see, you can make a shortcut, that leads to an action immediately, or you can make one, that just inits a character sequence and then you have to type one (or more) characters to cause an action to take place as shown in the example further above.

So if you are not happy with the default bindings, feel free to customize them as you like. Here's a link to the bash manual for more information.


Here's how you can do it

By default, the Terminal has these shortcuts to move (left and right) word-by-word:

  • esc+B (left)
  • esc+F (right)

You can configure alt+ and to generate those sequences for you:

  • Open Terminal preferences (cmd+,);
  • At Settings tab, select Keyboard and double-click ? ? if it's there, or add it if it's not.
  • Set the modifier as desired, and type the shortcut key in the box: esc+B, generating the text \033b (you can't type this text manually).
  • Repeat for word-right (esc+F becomes \033f)

Alternatively, you can refer to this blog post over at textmate:

http://blog.macromates.com/2006/word-movement-in-terminal/


As answered previously, you can add set -o vi in your ~/.bashrc to use vi/vim key bindings, or else you can add following part in .bashrc to move with Ctrl and arrow keys:

# bindings to move 1 word left/right with ctrl+left/right in terminal, just some apple stuff!
bind '"\e[5C": forward-word'
bind '"\e[5D": backward-word'
# bindings to move 1 word left/right with ctrl+left/right in iTerm2, just some apple stuff!
bind '"\e[1;5C": forward-word'
bind '"\e[1;5D": backward-word'

To start effect of these lines of code, either source ~/.bashrc or start a new terminal session.


I have Alt+/ working: open Preferences » Settings » Keyboard, set the entry for option cursor left to send string to shell: \033b, and set option cursor right to send string to shell: \033f. You can also use this for other Control key combinations.


If you happen to be a Vim user, you could try bash's vim mode. Run this or put it in your ~/.bashrc file:

set -o vi

By default you're in insert mode; hit escape and you can move around just like you can in normal-mode Vim, so movement by word is w or b, and the usual movement keys also work.


In Bash, these are bound to Esc-B and Esc-F. Bash has many, many more keyboard shortcuts; have a look at the output of bind -p to see what they are.


Here's how you can do it

By default, the Terminal has these shortcuts to move (left and right) word-by-word:

  • esc+B (left)
  • esc+F (right)

You can configure alt+ and to generate those sequences for you:

  • Open Terminal preferences (cmd+,);
  • At Settings tab, select Keyboard and double-click ? ? if it's there, or add it if it's not.
  • Set the modifier as desired, and type the shortcut key in the box: esc+B, generating the text \033b (you can't type this text manually).
  • Repeat for word-right (esc+F becomes \033f)

Alternatively, you can refer to this blog post over at textmate:

http://blog.macromates.com/2006/word-movement-in-terminal/


For some reason, my terminal's option+arrow weren't working. To fix this on macOS 10.15.6, I opened the terminal app's preferences, and had to set the bindings.

Option-left = \033b
Option-right = \033e

Keyboard settings in Mac terminal app

For some reason, the option-right I had was set up to be \033f. Now that it's fixed, I can freely skip around words in the termianl again.


If you check Use option as meta key in the keyboard tab of the preferences, then the default emacs style commands for forward- and backward-word and ?F (Alt+F) and ?B (Alt+B) respectively.

I'd recommend reading From Bash to Z-Shell. If you want to increase your bash/zsh prowess!


For some reason, my terminal's option+arrow weren't working. To fix this on macOS 10.15.6, I opened the terminal app's preferences, and had to set the bindings.

Option-left = \033b
Option-right = \033e

Keyboard settings in Mac terminal app

For some reason, the option-right I had was set up to be \033f. Now that it's fixed, I can freely skip around words in the termianl again.


Under iterm2's Preferences > Profile > Keys, you click the + below Key Mappings and record a new shortcut. For Action, select Send Escape Sequence and type b or f for backwards and forwards respectively.

When I tried to record one for (Ctrl+?), I noticed in the Keyboard Shortcut field that the arrow never showed up. Turns out I had to disable the default mac's System Preferences > Keyboard > Shortcuts > Mission Control shorcuts first to get things to work, as they'll override iterm2's default shortcuts. Should be true for the standard terminal app, too.

Keyboard system preferences


Actually there is a much better approach. Hold option ( alt on some keyboards) and press the arrow keys left or right to move by word. Simple as that.

option
option

Also ctrle will take you to the end of the line and ctrla will take you to the start.


Hold down the Option key and click where you'd like the cursor to move


On Mac OS X - the following keyboard shortcuts work by default. Note that you have to make Option key act like Meta in Terminal preferences (under keyboard tab)

  • alt (?)+F to jump Forward by a word
  • alt (?)+B to jump Backward by a word

I have observed that default emacs key-bindings for simple text navigation seem to work on bash shells. You can use

  • alt (?)+D to delete a word starting from the current cursor position
  • ctrl+A to jump to start of the line
  • ctrl+E to jump to end of the line
  • ctrl+K to kill the line starting from the cursor position
  • ctrl+Y to paste text from the kill buffer
  • ctrl+R to reverse search for commands you typed in the past from your history
  • ctrl+S to forward search (works in zsh for me but not bash)
  • ctrl+F to move forward by a char
  • ctrl+B to move backward by a char
  • ctrl+W to remove the word backwards from cursor position

Here's how you can do it

By default, the Terminal has these shortcuts to move (left and right) word-by-word:

  • esc+B (left)
  • esc+F (right)

You can configure alt+ and to generate those sequences for you:

  • Open Terminal preferences (cmd+,);
  • At Settings tab, select Keyboard and double-click ? ? if it's there, or add it if it's not.
  • Set the modifier as desired, and type the shortcut key in the box: esc+B, generating the text \033b (you can't type this text manually).
  • Repeat for word-right (esc+F becomes \033f)

Alternatively, you can refer to this blog post over at textmate:

http://blog.macromates.com/2006/word-movement-in-terminal/


Actually there is a much better approach. Hold option ( alt on some keyboards) and press the arrow keys left or right to move by word. Simple as that.

option
option

Also ctrle will take you to the end of the line and ctrla will take you to the start.


If you check Use option as meta key in the keyboard tab of the preferences, then the default emacs style commands for forward- and backward-word and ?F (Alt+F) and ?B (Alt+B) respectively.

I'd recommend reading From Bash to Z-Shell. If you want to increase your bash/zsh prowess!


Actually it depends on what shell you use, however most shells have similar bindings. The bindings you are referring to (e.g. Ctrl+A and Ctrl+E) are bindings you will find in many other programs and they are used for ages, BTW also work in most UI apps.

Here's a look of default bindings for Bash:

Most Important Bash Keyboard Shortcuts

Please also note that you can customize them. You need to create a file, name as you wish, I named mine .bash_key_bindings and put it into my home directory. There you can set some general bash options and you can also set key bindings. To make sure they are applied, you need to modify a file named ".bashrc" that bash reads in upon start-up (you must create it, if it does not exist) and make the following call there:

bind -f ~/.bash_key_bindings

~ means home directory in bash, as stated above, you can name the file as you like and also place it where you like as long as you feed the right path+name to bind.

Let me show you some excerpts of my .bash_key_bindings file:

set meta-flag on
set input-meta on
set output-meta on
set convert-meta off
set show-all-if-ambiguous on
set bell-style none
set print-completions-horizontally off

These just set a couple of options (e.g. disable the bell; this can be all looked up on the bash webpage).

"A": self-insert
"B": self-insert
"C": self-insert
"D": self-insert
"E": self-insert
"F": self-insert
"G": self-insert
"H": self-insert
"I": self-insert
"J": self-insert

These make sure that the characters alone just do nothing but making sure the character is "typed" (they insert themselves on the shell).

"\C-dW": kill-word
"\C-dL": kill-line
"\C-dw": backward-kill-word
"\C-dl": backward-kill-line
"\C-da": kill-line

This is quite interesting. If I hit Ctrl+D alone (I selected d for delete), nothing happens. But if I then type a lower case w, the word to the left of the cursor is deleted. If I type an upper case, however, the word to the right of the cursor is killed. Same goes for l and L regarding the whole line starting from the cursor. If I type an "a", the whole line is actually deleted (everything before and after the cursor).

I placed jumping one word forward on Ctrl+F and one word backward on Ctrl+B

"\C-f": forward-word
"\C-b": backward-word

As you can see, you can make a shortcut, that leads to an action immediately, or you can make one, that just inits a character sequence and then you have to type one (or more) characters to cause an action to take place as shown in the example further above.

So if you are not happy with the default bindings, feel free to customize them as you like. Here's a link to the bash manual for more information.


If you check Use option as meta key in the keyboard tab of the preferences, then the default emacs style commands for forward- and backward-word and ?F (Alt+F) and ?B (Alt+B) respectively.

I'd recommend reading From Bash to Z-Shell. If you want to increase your bash/zsh prowess!


Use Natural Text Editing preset!

enter image description here

Essentially it binds, among other key sequences, Option + LeftArrow to ^[b sequence and Option + RightArrow to ^[f

This works in fish and bash, as well as in psql terminal.


Hold down the Option key and click where you'd like the cursor to move


Examples related to macos

Problems with installation of Google App Engine SDK for php in OS X dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac Could not install packages due to an EnvironmentError: [Errno 13] How do I install Java on Mac OSX allowing version switching? Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Can't compile C program on a Mac after upgrade to Mojave You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user) How can I install a previous version of Python 3 in macOS using homebrew? Could not install packages due to a "Environment error :[error 13]: permission denied : 'usr/local/bin/f2py'"

Examples related to terminal

Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Can't compile C program on a Mac after upgrade to Mojave Flutter command not found VSCode Change Default Terminal How to switch Python versions in Terminal? How to open the terminal in Atom? Color theme for VS Code integrated terminal How to edit a text file in my terminal How to open google chrome from terminal? Switch between python 2.7 and python 3.5 on Mac OS X

Examples related to keyboard-shortcuts

Collapse all methods in Visual Studio Code Is there a keyboard shortcut (hotkey) to open Terminal in macOS? Jupyter/IPython Notebooks: Shortcut for "run all"? Any way (or shortcut) to auto import the classes in IntelliJ IDEA like in Eclipse? How do I duplicate a line or selection within Visual Studio Code? How do I search for files in Visual Studio Code? OS X Terminal shortcut: Jump to beginning/end of line window.close() doesn't work - Scripts may close only the windows that were opened by it Comment shortcut Android Studio Column/Vertical selection with Keyboard in SublimeText 3