bash/readline 相当于 vi 模式下的 escape-dot

发布于 2024-11-26 10:00:02 字数 191 浏览 1 评论 0原文

最近在 bash 中切换到 vi 模式后,我想念的一件事是 esc . 获取最后一个命令的最后一个参数。

我知道 ctrl _,但我最终总是点击 ctrl -

是否还有其他相当于此功能的 vi 模式?

Having recently switched to vi-mode in bash, the one thing I miss is esc . to get the last argument of the last command.

I know about ctrl _, but I always end up hitting ctrl - instead.

Is there another vi-mode equivalent for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

夏了南城 2024-12-03 10:00:02

我相信最接近您想要的解决方案是:

在您的 .bashrc 中,在“set -o vi”之后...

set -o vi
bind -m vi-command ".":insert-last-argument

这告诉您的 bash 在“.”时调用“insert-last-argument”操作在 vi 命令模式下使用。这当然意味着你失去了正常的“。” VI的功能;但如果你像我一样,你会更喜欢这个。

附录
您可能还希望 Ctrl-ACtrl-ECtrl-WCtrl-L 工作(这些是我最想念的):

bind -m vi-command ".":insert-last-argument
bind -m vi-insert "\C-l.":clear-screen
bind -m vi-insert "\C-a.":beginning-of-line
bind -m vi-insert "\C-e.":end-of-line
bind -m vi-insert "\C-w.":backward-kill-word

I believe the closest solution to what you want is this:

In your .bashrc, right after "set -o vi"...

set -o vi
bind -m vi-command ".":insert-last-argument

This tells your bash to invoke the "insert-last-argument" action when '.' is used in vi-command mode. This of course means that you lose the normal "." functionality of VI; but if you are like me, you'll prefer this.

Addendum:
You may also want Ctrl-A, Ctrl-E, Ctrl-W and Ctrl-L to work (those were the ones I was missing the most):

bind -m vi-command ".":insert-last-argument
bind -m vi-insert "\C-l.":clear-screen
bind -m vi-insert "\C-a.":beginning-of-line
bind -m vi-insert "\C-e.":end-of-line
bind -m vi-insert "\C-w.":backward-kill-word
南城追梦 2024-12-03 10:00:02

您还可以使用以下命令在 vi 模式下恢复 emacs“转义点插入最后一个参数”行为:

bindkey -v '\e.' insert-last-word

You can also use the following to restore the emacs "escape-dot inserts last argument" behaviour in vi mode:

bindkey -v '\e.' insert-last-word
追风人 2024-12-03 10:00:02

通过更改或添加 ~/.inputrc

要在 vi 模式下恢复某些 bash 功能,只需更改或添加 ~/.inputrc 即可,如下所示:

set completion-ignore-case on
set show-all-if-ambiguous on
set show-all-if-unmodified on

set editing-mode vi
set keymap vi-insert

$if mode=vi
"\C-a": beginning-of-line
"\C-e": end-of-line
"\C-l": clear-screen
"\C-n": next-history
"\C-p": previous-history
"\C-w": backward-kill-word

"\e.": yank-last-arg
"\e_": yank-last-arg
$endif

这里有 更多可绑定 readline bash 命令

By altering or adding ~/.inputrc

To restore certain bash goodies in vi-mode, simply alter or add ~/.inputrc like this:

set completion-ignore-case on
set show-all-if-ambiguous on
set show-all-if-unmodified on

set editing-mode vi
set keymap vi-insert

$if mode=vi
"\C-a": beginning-of-line
"\C-e": end-of-line
"\C-l": clear-screen
"\C-n": next-history
"\C-p": previous-history
"\C-w": backward-kill-word

"\e.": yank-last-arg
"\e_": yank-last-arg
$endif

Here are more bindable readline bash commands.

过去的过去 2024-12-03 10:00:02

我总是使用 alt . 来获取最后一个命令的最后一个参数。

此外, !$ 将为您提供最后执行的命令的最后一个参数。您可以使用感叹号做很多很酷的事情,只需查看 bash 的手册页并搜索历史扩展即可。

I always used alt . to get the last argument of the last command.

Also, the !$ will give you the last argument of the last command executed. There are a bunch of cool things you can do with the exclamation point, just check out the man page for bash and search for History Expansion.

以往的大感动 2024-12-03 10:00:02

只使用 $_ bash 变量怎么样?

How about just using $_ bash variable?

时光病人 2024-12-03 10:00:02

我很确定您仍然可以使用 vi 模式的等效内容,应该是“ESC +”。

I'm pretty sure you can still use the equivalent for vi mode, which should be "ESC + ."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文