1

Just saw a tip here, but I'm not able to make it fully working.

Here is how it plays out:

  • type echo abc def, then hit enter.
  • key in <Up><Alt-T>, that echo abc def will becomes echo def abc

However, I'm not able to make what the above tip fully works. I.e., echo /long/path/to/dir_a /very/long/path/to/dir_b were never get properly swapped -- instead I get echo /long/path/to/dir_a /very/long/path/to/b_dir. The comments below the tip get similar results too.

Anyone knows how the tip author made it worked?

xpt
  • 20,363
  • 37
  • 127
  • 216
  • Cross-site duplicate: https://unix.stackexchange.com/questions/187600/how-do-i-swap-the-two-last-command-line-arguments – tripleee Aug 09 '19 at 10:48
  • @tripleee, please don't just mark it duplicate because the title is the same -- look at the solution there. I agree with your comment _"The real solution is to modify the word separator"_ but that solution is not there in your referenced Cross-site "duplicate", https://unix.stackexchange.com/questions/187600/. Thanks – xpt Aug 09 '19 at 11:54
  • I have not marked this as a duplicate, and indeed couldn't. I have simply left a comment. – tripleee Aug 09 '19 at 13:41
  • For that discussion, see also https://unix.stackexchange.com/questions/78990/what-are-the-readline-word-separators - it looks like you can't change the delimiter cbut Bash 4 brings some relief in the form of additional readline commands). – tripleee Aug 09 '19 at 13:48
  • Tangentially see also https://stackoverflow.com/questions/1357191/changing-word-delimiters-in-bash – tripleee Aug 09 '19 at 13:49

2 Answers2

0

Alt+t is swapping a word under cursor with the previous word. Since '/' is treated as word separator you get the weird behavior.

Try doing Ctrl+e Escape+t.

  • 1
    Esc-t and Alt-t both do the same thing for me (as you would expect). The real solution is to modify the word separator or try a different approach which operates on tokens rather than on "words". – tripleee Aug 09 '19 at 10:47
0

vi mode can do this:

set -o vi

Then stay cursor at the first word (e. g. Esc-2w) and press hdeep.