Bash – Moving by whitespace-delimited word in bash/readline

bashreadline

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.

Best Answer

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.

Related Question