TyMac
TyMac

Reputation: 803

Keybindings with ZSH

Can anyone tell me how to move back a word in ZSH? Ctrl+b will move back a character but not an entire word.

For instance a log command like this:

knife zero bootstrap [email protected] --sudo-preserve-home --ssh-user mbigglesworth --sudo --policy-name linux_mint_wkstn -N linuxmint-vm -VV

...is painful to get to the middle of!

Upvotes: 6

Views: 16549

Answers (3)

Alter
Alter

Reputation: 1223

The answer looks a bit outdated, this method did not work for me, at least not on a MacBook with macOS Sequoia(15.1.1). One can do the following if you do not know which keys to bind. Open the terminal, type cat, and hit Enter. In the next line, press the key combination to bind. The output should be like this for option + backward: ^[[1;3D. Do the same for the forward word

You need to add that in the .zshrc file as follows:

...
bindkey "^[[1;3D" backward-word
bindkey "^[[1;3C" forward-word
...

source .zshrc after saving the changes

Upvotes: 1

Chris Kitching
Chris Kitching

Reputation: 2655

Ctrl+Left or Ctrl+Right to move back and forward one word.

It does, however, depend heavily on your configuration. Read more here.

A list of other handy default keybindings is here

Upvotes: 1

sudavid4
sudavid4

Reputation: 1141

ESCAPE+b or ESCAPE+f to move back one word or forward one word respectively

EDIT

The mentioned above are the defaults(as far as I'm concerned)

@TyMac mentions that the defaults are uppercase in his system though (ESCAPE-B, ESCAPE-F)

You may perfectly set them manually by inserting the following lines in your zshrc

bindkey "^[b" backward-word 
bindkey "^[f" forward-word

in case you don't like the defaults you may set it to some different key combo using this same syntax (I would suggest that it's preferable to use the defaults though but that's just personal opinion)

Upvotes: 10

Related Questions