Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In bash/readline, if you want to navigate through a command, often you have things like:

cat /home/foo/bar.txt /home/bar/baz.txt

If my cursor is at the end of the line (^e), and I want to move back to the start of the second argument, how do I move to the (next/previous) whitespace?

Readline has built-in Meta-f (forward) and Meta-b (backwards), but these will stop at the slashes in the paths, not move all the way to the whitespace.

vim has W and B which will do this, but vim movement mode is not enabled in readline/bash by default.

share|improve this question

1 Answer 1

You can use vim movement commands in readline/bash even while still in emacs movement mode. The relevant readline commands are vi-fWord and vi-bWord. You can bind them to keyboard shortcuts such as CTRL-f and CTRL-b with the following in your .bash_profile:

bind '"\C-f":vi-fWord'
bind '"\C-b":vi-bWord'

Note that the double quoting is significant.

You can confirm that the bindings are working by running bind -p

share|improve this answer
1  
As I like having my readline configuration reside completely within ~/.inputrc , you can drop the bind and surrounding single quotes and add it directly to ~/.inputrc –  Roshan Nov 6 '13 at 12:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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