5

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 mbigglesworth@10.10.1.108 --sudo-preserve-home --ssh-user mbigglesworth --sudo --policy-name linux_mint_wkstn -N linuxmint-vm -VV

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

Xavier Guihot
  • 54,987
  • 21
  • 291
  • 190
TyMac
  • 783
  • 2
  • 9
  • 32

2 Answers2

9

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)

sudavid4
  • 1,081
  • 6
  • 14
  • that's strange. could you please try running these commands and try that again? if it works you may add them to your zshrc: `bindkey "^[b" backward-word` `bindkey "^[f" forward-word` you might also try to run `bindkey | egrep '(backward|forward)-word'` and see if they are already bound to something. what do you get? – sudavid4 Feb 16 '18 at 10:38
  • also, what version of zsh are you using? `zsh --version` if you are using the mac system zsh you might want to consider downloading a more updated version. recommended way of doing this is with [homebrew](https://brew.sh/) `brew install zsh` – sudavid4 Feb 16 '18 at 10:51
  • zsh 5.3.1 (x86_64-apple-darwin15.6.0) – TyMac Feb 16 '18 at 23:41
  • bindkey | egrep '(backward|forward)-word' = "^[B" backward-word - capital B :) – TyMac Feb 16 '18 at 23:43
1

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

Xavier Guihot
  • 54,987
  • 21
  • 291
  • 190
Chris Kitching
  • 2,559
  • 23
  • 37
  • 1
    CTRL + the left or right arrow key? This is not working on my Mac. I have the default oh-my-zsh zshrc profile. Is there something I need to add? – TyMac Feb 08 '18 at 18:47