In bash line editing (or in any program that uses GNU readline), Meta-f moves to the right by one "word" and Meta-b move to the left by one "word", where a "word" is composed of letters and digits. These are the forward-word and backward-word commands. (Meta-f can be either the Alt modifier key or a prefix Escape key.)

For example, if I've typed

cat /etc/motd

then repeatedly typing Meta-b moves the cursor to the m, then the e, then the c.

Is there a command that moves similarly, but by whitespace-delimited words, so /etc/motd is a single word?

(I often work with very long file paths, and I'd like to be able to skip over them easily. My workaround is either to type the existing word-move commands repeatedly, or to type ^X ^E to launch an editor.)

In vim, w and b move forward and back by words, and W and B move by whitespace-delimited words. I'm looking for something similar.

I've looked through the readline documentation, and I suspect the answer is no, but perhaps I've missed something.


You can add this:

set keymap vi-move
"\e[EMACS~": emacs-editing-mode
set keymap emacs
"\e[VI~": vi-movement-mode
"\ed": "\e[VI~dW\e[EMACS~"
"\ef": vi-fWord
"\eb": vi-bWord

To your inputrc or use zsh where that's more easily customizable. See this answer to another Q&A for details.


If you do set -o vi readline takes vim style commands and then w/W and b/B have the same word/WORD behavior as in vim editor. I routinely use W/B to skip over full paths, urls, etc. when editing the command line. I see from the output of bind -l that there is a vim-forward-word/vim-forward-bigword pair and the backward equivalent.

Looking at the Bash man page I also see shell-forward-word and shell-backward-word. These are "words" delimited by "shell metacharacters" which are characters "that, when unquoted, separate words"

Can't say I have much experience using bind directly but I just tried bind '"\C-x": shell-backward-word' and now Ctrl+x in edit mode does jump backwards over more than alphanumeric characters...to the next whitespace to be specific.

  • Try it on "foo bar" or $(echo foo bar) though. It's more like motions based on shell tokens – Stéphane Chazelas Oct 7 '17 at 6:29
  • Yes, I said "when unquoted" which would not apply to "foo bar", for example. OP specifically mentioned long paths so I thought the shell-*-word functions would be of interest despite the "shell metacharacter" aspect if for some reason the vim-*-word functions were a problem. – B Layer Oct 7 '17 at 6:49
  • Good points. I read your answer too quickly, – Stéphane Chazelas Oct 7 '17 at 6:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.