Skip to main content
Added POSIX note
Source Link
Quasímodo
  • 19.4k
  • 4
  • 41
  • 78

That really looks like a bug, but actually Bash is just trying to follow the POSIX specified behavior of _,

[count]_
Append a <space> after the current character position and then append the last bigword in the previous input line after the <space>. Then enter insert mode after the last character just appended. With a number count, append the countth bigword in the previous line.

As a workaround, add this to your ~/.inputrc. You can change the Alt-h\M-h to some other unbound key if you want.

set editing-mode vi
set keymap vi-command
"\M-h":history-expand-line
".":"a!$\e\M-hA"

Now, open a new terminal. Upon striking . in normal mode,

  • !$ is insterted in the command-line.
  • \e (means Esc) goes back to normal mode.
  • \M-h triggers history-expand-line action, which expands $! to the value of the last argument.
  • A moves to the end-of-the line and enters insert mode.
$ echo "X Y Z"
X Y Z
$ "X Y Z" #<ESC>. inserts this
$ echo "X Y Z"
X Y Z
$ cat "X Y Z" #cat <ESC>. inserts this

As a workaround, add this to your ~/.inputrc. You can change the Alt-h to some other unbound key if you want.

set editing-mode vi
set keymap vi-command
"\M-h":history-expand-line
".":"a!$\e\M-hA"

Now, open a new terminal. Upon striking . in normal mode,

  • !$ is insterted in the command-line.
  • \e (means Esc) goes back to normal mode.
  • \M-h triggers history-expand-line action, which expands $! to the value of the last argument.
  • A moves to the end-of-the line and enters insert mode.
$ echo "X Y Z"
X Y Z
$ "X Y Z" #<ESC>. inserts this
$ echo "X Y Z"
X Y Z
$ cat "X Y Z" #cat <ESC>. inserts this

That really looks like a bug, but actually Bash is just trying to follow the POSIX specified behavior of _,

[count]_
Append a <space> after the current character position and then append the last bigword in the previous input line after the <space>. Then enter insert mode after the last character just appended. With a number count, append the countth bigword in the previous line.

As a workaround, add this to your ~/.inputrc. You can change the \M-h to some other unbound key if you want.

set editing-mode vi
set keymap vi-command
"\M-h":history-expand-line
".":"a!$\e\M-hA"

Now, open a new terminal. Upon striking . in normal mode,

  • !$ is insterted in the command-line.
  • \e (means Esc) goes back to normal mode.
  • \M-h triggers history-expand-line action, which expands $! to the value of the last argument.
  • A moves to the end-of-the line and enters insert mode.
$ echo "X Y Z"
X Y Z
$ "X Y Z" #<ESC>. inserts this
$ echo "X Y Z"
X Y Z
$ cat "X Y Z" #cat <ESC>. inserts this
"set editing-mode vi" line was missing
Source Link
Quasímodo
  • 19.4k
  • 4
  • 41
  • 78

As a workaround, add this to your ~/.inputrc. You can change the Alt-h to some other unbound key if you want.

set editing-mode vi
set keymap vi-command
"\M-h":history-expand-line
".":"a!$\e\M-hA"

Now, uponopen a new terminal. Upon striking . in normal mode,

  • !$ is insterted in the command-line.
  • \e (means Esc) goes back to normal mode.
  • \M-h triggers history-expand-line action, which expands $! to the value of the last argument.
  • A moves to the end-of-the line and enters insert mode.
$ echo "X Y Z"
X Y Z
$ "X Y Z" #<ESC>. inserts this
$ echo "X Y Z"
X Y Z
$ cat "X Y Z" #cat <ESC>. inserts this

As a workaround, add this to your ~/.inputrc. You can change the Alt-h to some other unbound key if you want.

set keymap vi-command
"\M-h":history-expand-line
".":"a!$\e\M-hA"

Now, upon striking . in normal mode,

  • !$ is insterted in the command-line.
  • \e (means Esc) goes back to normal mode.
  • \M-h triggers history-expand-line action, which expands $! to the value of the last argument.
  • A moves to the end-of-the line and enters insert mode.
$ echo "X Y Z"
X Y Z
$ "X Y Z" #<ESC>. inserts this
$ echo "X Y Z"
X Y Z
$ cat "X Y Z" #cat <ESC>. inserts this

As a workaround, add this to your ~/.inputrc. You can change the Alt-h to some other unbound key if you want.

set editing-mode vi
set keymap vi-command
"\M-h":history-expand-line
".":"a!$\e\M-hA"

Now, open a new terminal. Upon striking . in normal mode,

  • !$ is insterted in the command-line.
  • \e (means Esc) goes back to normal mode.
  • \M-h triggers history-expand-line action, which expands $! to the value of the last argument.
  • A moves to the end-of-the line and enters insert mode.
$ echo "X Y Z"
X Y Z
$ "X Y Z" #<ESC>. inserts this
$ echo "X Y Z"
X Y Z
$ cat "X Y Z" #cat <ESC>. inserts this
The previous version had problems with words with spaces. This one does not.
Source Link
Quasímodo
  • 19.4k
  • 4
  • 41
  • 78

As a workaround, add this to your ~/.inputrc. You can change the Alt-h to some other unbound key if you want.

set keymap vi-command
"\M-h":yankhistory-lastexpand-argline
".":"\M"a!$\e\M-h\eBhxA"hA"

Now, upon striking . in normal mode, yank-last-arg is issued, and

  • !$ is insterted in the command-line.
  • \e (means Esc) goes back to normal mode.
  • B\M-h moves back to the beginning of the argument.
  • triggers hhistory-expand-line moves back one character.
  • action, which expands x$! deletesto the character undervalue of the cursorlast argument.
  • A moves to the end-of-the line and enters insert mode.

Below, {Cursor} represents the final cursor position and # are comments.

$ echo XYZ"X Y Z"
XYZX Y Z
$ XYZ{Cursor}"X #HitY <ESC>Z" #<ESC>. inserts this
$ echo XYZ
XYZ"X Y Z"
#X NowY tryZ
$ cat <ESC>., it"X shouldY giveZ" you#cat this:
$<ESC>. catinserts XYZ{Cursor}this

As a workaround, add this to your ~/.inputrc. You can change the Alt-h to some other unbound key if you want.

set keymap vi-command
"\M-h":yank-last-arg
".":"\M-h\eBhxA"

Now, upon striking . in normal mode, yank-last-arg is issued, and

  • \e (means Esc) goes back to normal mode.
  • B moves back to the beginning of the argument.
  • h moves back one character.
  • x deletes the character under the cursor.
  • A moves to the end-of-the line and enters insert mode.

Below, {Cursor} represents the final cursor position and # are comments.

$ echo XYZ
XYZ
$ XYZ{Cursor} #Hit <ESC>. inserts this
$ echo XYZ
XYZ
# Now try cat <ESC>., it should give you this:
$ cat XYZ{Cursor}

As a workaround, add this to your ~/.inputrc. You can change the Alt-h to some other unbound key if you want.

set keymap vi-command
"\M-h":history-expand-line
".":"a!$\e\M-hA"

Now, upon striking . in normal mode,

  • !$ is insterted in the command-line.
  • \e (means Esc) goes back to normal mode.
  • \M-h triggers history-expand-line action, which expands $! to the value of the last argument.
  • A moves to the end-of-the line and enters insert mode.
$ echo "X Y Z"
X Y Z
$ "X Y Z" #<ESC>. inserts this
$ echo "X Y Z"
X Y Z
$ cat "X Y Z" #cat <ESC>. inserts this
Source Link
Quasímodo
  • 19.4k
  • 4
  • 41
  • 78
Loading