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

pab*_*sso 42 linux mac terminal bash shell

我在 Linux shell 中怀念的一件事是Alt+Dot快捷方式。它的作用是插入上一个命令的最后一个参数。这看起来是一个微不足道的技术,但它真的很有用。

即如果你输入这个:

$ ls /Applications/MAMP/conf/apache/
Run Code Online (Sandbox Code Playgroud)

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

$ cd 'alt+dot'
Run Code Online (Sandbox Code Playgroud)

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

然而,虽然这两种替代方法都插入了您使用的最后一个参数,但它们无法像重复键入Alt+Dot那样在命令历史记录中向后滚动。

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

Ric*_*ins 38

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

  • 对于 iTerm,打开首选项,配置文件 > 键,选择选项键作为底部的`+Esc`。 (11认同)
  • 顺便说一句,我应该提到,虽然这解决了 alt+dot 问题,但它弄乱了其他键盘组合,如 ]、} 或 |。我的键盘(西班牙语)使用 option+somekey 来输入它们。好吧,你不能拥有这一切。 (5认同)

小智 26

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

  • 我可以按它很多次,但它只是第一次工作 (4认同)
  • 没关系,你是对的。你只需要释放 esc 再次按下它,然后它就会按预期滚动历史。将选项键视为元会弄乱其他一些快捷方式,这是最干净的解决方案。 (2认同)
  • 最简单的方法是在终端首选项中选中“使用选项键作为元”,如理查德·霍斯金斯的回答中所述。 (2认同)

Dou*_*ris 5

使用option+.

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


贴几个相关部分:

   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.
Run Code Online (Sandbox Code Playgroud)