Mac 中 Alt+Dot 的等效/替代键

Mac 中 Alt+Dot 的等效/替代键

我怀念 Linux shell 的一件事是Alt+点快捷方式。它的作用是插入前一个命令的最后一个参数。这似乎是一种微不足道的技术,但确实很有用。

例如如果你输入以下内容:

$ ls /Applications/MAMP/conf/apache/

下次您只需键入命令 + 快捷方式,参数就会为您完成。

$ cd 'alt+dot'

在 Mac 上我知道 2 个选择;按Esc+点或输入!$!*魔法空间设置

然而,虽然这两种方法都会插入你最后使用的参数,但它们无法像键入那样在命令历史记录中回滚Alt+点反复地这样做。

我现在可以接受这个选择,但我很想知道是否有人知道更好的方法。

答案1

您可以多次按Escape+ .,它的作用与Alt+相同.
但是,像您一样,我发现它比Alt+更麻烦.

答案2

在 Terminal.app 中,选择“首选项”->“设置”,选择“键盘”选项卡。确保选中“使用 Option 键作为 Meta”。

答案3

使用option+.

请注意,这是 bash 的功能,而不是 linux 的功能。Mac 上也有 bash。Alt-. 是内置 bash 函数的快捷键insert-last-argument。阅读阅读线部分bash 手册页有关如何将其绑定到不同的组合键。


粘贴几个相关部分:

   Readline Initialization
       Readline  is customized by putting commands in an initialization file (the
       inputrc file).
       The  default key-bindings may be changed with an inputrc file.  Other pro-
       grams that use this library may add their own commands and bindings.

       For example, placing

              M-Control-u: universal-argument
       or
              C-Meta-u: universal-argument
       into the inputrc would make M-C-u execute  the  readline  command  univer-
       sal-argument.

   Readline Key Bindings
       The  syntax  for  controlling  key bindings in the inputrc file is simple.
       All that is required is the name of the command or the text of a macro and
       a  key  sequence to which it should be bound. The name may be specified in
       one of two ways: as a symbolic key name, possibly with Meta-  or  Control-
       prefixes, or as a key sequence.

       When using the form keyname:function-name or macro, keyname is the name of
       a key spelled out in English.  For example:

              Control-u: universal-argument
              Meta-Rubout: backward-kill-word
              Control-o: "> output"

       In the above example, C-u is bound  to  the  function  universal-argument,
       M-DEL is bound to the function backward-kill-word, and C-o is bound to run
       the macro expressed on the right hand side (that is, to  insert  the  text
       ``> output'' into the line).

       In  the  second form, "keyseq":function-name or macro, keyseq differs from
       keyname above in that strings denoting an entire key sequence may be spec-
       ified  by placing the sequence within double quotes.  Some GNU Emacs style
       key escapes can be used, as in the following  example,  but  the  symbolic
       character names are not recognized.

              "\C-u": universal-argument
              "\C-x\C-r": re-read-init-file
              "\e[11~": "Function Key 1"


   Commands for Manipulating the History
       insert-last-argument (M-., M-_)
              A synonym for yank-last-arg.

答案4

如果您使用 iTerm2,请执行以下操作:

  1. 选择首选项 -> 配置文件 ->(选择当前活动的配置文件或默认配置文件)-> 键
  2. 在下面按键映射菜单按小“+”按钮
  3. 点击键盘快捷键
  4. 按 Option+. (或您想要用作 Alt+Dot 的任何其他组合键)
  5. 行动选择发送十六进制代码
  6. 在下面出现的小文本字段中输入:0x1b 0x2e
  7. 按“确定”按钮创建新的键映射
  8. 享受 ;-)

相关内容