0

I'm wondering if it's possible to assign a key to go back or forward a full parameter in bash. That is, if I have:

prompt> somecmd a/b/c/d/e/f/g/h a_b_c_d_e_f_g`

on my terminal (and say the cursor is at the end), and I want to go to the beginning of the first parameter, I have to press alt-f 15 times (note: I'm using putty on a windows machine). I commonly work with command lines that are 500+ characters long, where most of the command line is paths with underscores in them. It would be really nice to able to skip to the previous (whitespace delimited) parameter instead of the previous word.

(note: I found one question, where it was suggested to use ^R followed by space, but this gives me the previous command rather than searching for the previous space for some reason).

1 Answer 1

0

I found a reference -- it took a bit of searching, so I'll post the answer here in hopes that it might save someone else some time. In ~/.bashrc, you can put:

bind '"\eOD":vi-backward-bigword'
bind '"\eOC":vi-forward-bigword'

note that \eOD repressent ctrl-forward-arrow on my specific terminal. To figure out binding for other keys or terminals, press ctrl-v followed by the key you want to assign to, and it will output the key pattern. In the key-patter, replace the ^[ with \e (so for example ^[OD changes to \eOD) and use that for your binding

You can also put the definition in ~.inputrc, which would look like:

"\eOC":vi-forward-bigword
"\eOD":vi-backward-bigword

You can use bind -P to check your bindings to see if it's bound properly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .