For a quick and simple solution add this to your inputrc (choose suitable keys for yourself):
"\e\C-b": shell-backward-kill-word
"\eh": shell-backward-word
"\e\C-f": shell-forward-word
# Swap the preceding two arguments (control + alt + t)
"\e\C-t": "\e\C-b\eh\C-y"
# Swap the preceding argument with the next (control + alt + p)
"\e\C-p": "\e\C-b\e\C-f\C-y"
In case of shell-*
versions of these functions words are delimited by non-quoted shell metacharacters.
metacharacter
A character that, when unquoted, separates words. A metacharacter is a space, tab, newline, or one of the following characters: ‘|’, ‘&’, ‘;’, ‘(’, ‘)’, ‘<’, or ‘>’.
Note: The cursor has to be after the second argument before pressing Ctrl+Alt+t, so it effectively pushes the argument before the cursor towards the beginning of the line.
$ true foo/bar.xyz even/without\ quotes.ok "too/too far.away"
^
$ true foo/bar.xyz "too/too far.away" even/without\ quotes.ok
^
$ true "too/too far.away" foo/bar.xyz even/without\ quotes.ok
^
Note: The cursor has to be after the first argument before pressing Ctrl+Alt+p, so it effectively pulls the argument before the cursor towards the end of the line.
$ true "too/too far.away" foo/bar.xyz even/without\ quotes.ok
^
$ true foo/bar.xyz "too/too far.away" even/without\ quotes.ok
^
$ true foo/bar.xyz even/without\ quotes.ok "too/too far.away"
^
control
(orCtrl
on Windows keyboards) rather thanAlt
. – iconoclast Oct 17 '14 at 16:06