代码之家  ›  专栏  ›  技术社区  ›  Recursion

vi或emacs的bash用法

  •  6
  • Recursion  · 技术社区  · 15 年前

    从编程的角度来看,当您将bash shell设置为使用vi或emacs时,

    set -o vi
    

    set -o emacs
    

    这里到底发生了什么?我读过一本书,它声称bash shell使用这些编辑器中的任何一个作为shell本身的输入,但我认为它可能使用了readline。

    4 回复  |  直到 15 年前
        1
  •  6
  •   miked    15 年前

    bash仍在使用readline。readline使用emacs或vi模式,并设置各种编辑器模式之间的模式切换。您可以检查基本源代码中的lib/readline文件夹,以查看各种键绑定。

        2
  •  1
  •   wallyk    15 年前

    根据《巴什鲁布丁手册》(1)(在Fedora 8上):

       set [--abefhkmnptuvxBCHP] [-o option] [arg ...]
    

    ……(跳过所有单个字母选项)

             -o option-name
                The option-name can be one of the following:

    ……

                emacs   Use  an  emacs-style  command  line  editing interface.  This is
                        enabled by default when the shell  is  interactive,  unless  the
                        shell is started with the --noediting option.
    
                vi      Use a vi-style command line editing interface.
    
    我将其解释为bash直接解释用于行编辑的命令。此选项只设置要使用的命令集。阅读行(3)见手册页。
        3
  •  1
  •   Dennis Williamson    15 年前

    它使用其中一个编辑器的用户熟悉的击键来编辑命令行。

    readline是为bash和其他程序提供该功能的工具。

    man bash :

    READLINE
           This is the library that handles reading input when using  an  interac‐
           tive shell, unless the --noediting option is given at shell invocation.
           Line editing is also used when using the -e option to the read builtin.
           By default, the line editing commands are similar to those of emacs.  A
           vi-style line editing interface is also available.  Line editing can be
           enabled  at  any  time  using  the -o emacs or -o vi options to the set
           builtin (see SHELL BUILTIN COMMANDS below).  To turn off  line  editing
           after  the  shell  is running, use the +o emacs or +o vi options to the
           set builtin.
    
        4
  •  1
  •   paxdiablo    15 年前

    据我所知, readline 是什么为bash提供了行编辑功能。

    一个条件是:当你按下 v 在vi命令模式下,你会被完全击溃 vi 用于编辑命令行的编辑器。

    man bash :

    读出线
    这是在使用交互式shell时处理读取输入的库,除非 --noediting 在shell调用时提供选项。默认情况下,行编辑命令与Emacs的命令类似。还提供了一个vi样式的行编辑界面。要在shell运行后关闭行编辑,请使用 +o emacs +o vi 选项到 set 建筑。

    当shell向您显示提示时(除非您处于非编辑模式),您将 已经 使用 读出线 . 您将处于Emacs模式或vi插入模式(这就是为什么您可以只使用 ESC 回到vi命令模式)。

    推荐文章