Kos*_*sak 8 command-line bash keyboard-shortcuts vi
我set -o vi在 bash 中使用设置。Alt+.此处的快捷方式(调用前一个命令的最后一个参数)在 emacs 模式下不起作用,那么 vi 的等效项是什么?
Mar*_*slo 11
有多种方法可以获取最后一个命令的最后一个参数:
将以下代码复制到您的~/.inputrc文件中
set editing-mode vi
# Insert Mode
set keymap vi-insert
"\e.":yank-last-arg
"\e_": yank-last-arg
Run Code Online (Sandbox Code Playgroud)
您可以使用我的 inputrc 文件。这里是 inputrc 手册insert-last-argument和yank-last-arg
例如:
?? (marslo@MarsloJiao ~) ->
?? # echo arg1 arg2 arg3 arg4 arg5
arg1 arg2 arg3 arg4 arg5
?? (marslo@MarsloJiao ~) ->
?? # echo !$
echo arg5
arg5
?? (marslo@MarsloJiao ~) ->
?? # echo arg1 arg2 arg3 arg4 arg5
arg1 arg2 arg3 arg4 arg5
?? (marslo@MarsloJiao ~) ->
?? # echo !!:$
echo arg5
arg5
?? (marslo@MarsloJiao ~) ->
?? # echo arg1 arg2 arg3 arg4 arg5
arg1 arg2 arg3 arg4 arg5
?? (marslo@MarsloJiao ~) ->
?? # echo !!:^
echo arg1
arg1
?? (marslo@MarsloJiao ~) ->
?? # echo arg1 arg2 arg3 arg4 arg5
arg1 arg2 arg3 arg4 arg5
?? (marslo@MarsloJiao ~) ->
?? # echo !!:2-4
echo arg2 arg3 arg4
arg2 arg3 arg4
Run Code Online (Sandbox Code Playgroud)
Shell Word Designator的手册显示:
!!:$
Run Code Online (Sandbox Code Playgroud)designates the last argument of the preceding command. This may be shortened to !$.0(零)
Run Code Online (Sandbox Code Playgroud)The 0th word. For many applications, this is the command word.n
Run Code Online (Sandbox Code Playgroud)The nth word.^
Run Code Online (Sandbox Code Playgroud)The first argument; that is, word 1.$
Run Code Online (Sandbox Code Playgroud)The last argument.%
Run Code Online (Sandbox Code Playgroud)The word matched by the most recent ‘?string?’ search.xy
Run Code Online (Sandbox Code Playgroud)A range of words; ‘-y’ abbreviates ‘0-y’.*
所有单词,除了第 0 个。这是“1-$”的同义词。如果事件中只有一个词,则使用“ ”不是错误;在这种情况下返回空字符串。X
Run Code Online (Sandbox Code Playgroud)Abbreviates ‘x-$’X-
Run Code Online (Sandbox Code Playgroud)Abbreviates ‘x-$’ like ‘x*’, but omits the last word.
例如:
?? (marslo@MarsloJiao ~) ->
?? # echo very-very-very-very-very-long-argument
very-very-very-very-very-long-argument
?? (marslo@MarsloJiao ~) ->
?? # echo $_
very-very-very-very-very-long-argument
?? (marslo@MarsloJiao ~) ->
?? # ls /usr/local/etc/
?? (marslo@MarsloJiao ~) ->
?? # cd $_
?? (marslo@MarsloJiao /usr/local/etc) ->
?? #
Run Code Online (Sandbox Code Playgroud)
在Shell Special Parameters的手册中:
_
(下划线。)在 shell 启动时,设置为用于调用在环境或参数列表中传递的正在执行的 shell 或 shell 脚本的绝对路径名。随后,在扩展后扩展到上一个命令的最后一个参数。还设置为用于调用在导出到该命令的环境中执行和放置的每个命令的完整路径名。检查邮件时,此参数保存邮件文件的名称。
在之后添加此行set -o vi:
bind -m vi-command ".":yank-last-argument # or insert-last-argument
Run Code Online (Sandbox Code Playgroud)
然后你可以像在 emacs 模式中一样使用Alt+ 。.
或者使用历史扩展,在两者中工作:
!$:p
Run Code Online (Sandbox Code Playgroud)