LinuxTOY 是一个致力于提供 Linux 相关资讯的专题站点。如果您发现了好用好玩的 Linux 东东并愿意发扬自由、分享的精神,可以点击顶部导航 Contact 按钮进行投稿。

Related entries

readline:好用的工具应该让更多人知道

[撰文/hmy]

或许很多人已经知道 readline,但是总有人不知道。readline 从字面上来理解,就是从“行”上面读取。实际上就是一个行编辑库,bash 在用,mysql 也在用,mutt 也在用。

通过 readline,可以方便的在命令行上面移动,增删,复制,粘贴,搜索。比如:

  • ctrl+r 可以搜索历史命令,很常用的一个
  • ctrl+a 到行首
  • ctrl+e 到行尾
  • ctrl+u 删除到行首
  • ctrl+k 删除到行尾
  • ctrl+l 类似 clear 命令效果
  • ctrl+y 粘贴

更多用法参考手册页。

署名 • 注明出处 • 非商业性使用

26 Comments

  1. 1 LanEast Commented @ 2008-08-19 8:24 pmReply to this comment

    嗯, 这个东西很好用, 我现在在firefox里面输入地址的时候都会想用ctrl+w来删除一个单词. 结果发现把标签页关了- -U

  2. 2 najja Commented @ 2008-08-19 8:42 pmReply to this comment

    囧,这个我是通过王垠的文章知道的

  3. 3 liufeng Commented @ 2008-08-19 8:42 pmReply to this comment

    我觉得没有必要在这里介绍一个再普遍不过的库了吧。文章里的快捷键用过Emacs的都知道。

  4. 4 Aspirin Commented @ 2008-08-19 8:56 pmReply to this comment

    用过Bash就知道了。。

    没必要用Emacs才知道。。

  5. 5 nino Commented @ 2008-08-19 8:57 pmReply to this comment

    我一直以为是bash提供的类Emacs快捷键

  6. 6 fireinice Commented @ 2008-08-19 8:58 pmReply to this comment

    firefox里想用emacs快捷键(也就是readline)的可以使用firemacs扩展

  7. 7 mifly Commented @ 2008-08-19 9:17 pmReply to this comment

    firemacs在用,不过有些快捷键和firefox的冲突。如果有快捷键开启关闭firemacs就完美了

  8. 8 cn.fyodor Commented @ 2008-08-19 9:20 pmReply to this comment

    # editing with vi-style, default is insert mode.
    set -o vi

  9. 9 w.q Commented @ 2008-08-19 10:15 pmReply to this comment

    和nino一样,我也一直以为bash的快捷键跟emacs类似……

  10. 10 liufeng Commented @ 2008-08-19 10:28 pmReply to this comment

    bash快捷键和emacs类似是因为两者都用了这个readline库,emacs、bash、readline都是GNU的作品。

  11. 11 liufeng Commented @ 2008-08-19 10:54 pmReply to this comment

    sorry,刚才我想当然了。查了一下emacs似乎并不依赖readline。bash是依赖readline的。
    不好意思。

  12. 12 LD Commented @ 2008-08-19 11:53 pmReply to this comment

    第一天知道,失败,学习

  13. 13 iveney Commented @ 2008-08-20 1:01 amReply to this comment

    真的很好用哦,推荐这个网址。
    http://www.bigsmoke.us/readline/shortcuts

  14. 14 Zer4tul Commented @ 2008-08-20 1:09 amReply to this comment

    readline和emacs快捷键类似是因为它们都是GNU的作品,而bash依赖readline提供CLI界面,因此它的快捷键也和emacs类似了。大致是这样

  15. 15 ql Commented @ 2008-08-20 3:12 amReply to this comment

    ctrl+y 粘贴

  16. 16 hmy Commented @ 2008-08-20 7:28 amReply to this comment

    呵呵,多谢楼上的纠正

  17. 17 Toy Commented @ 2008-08-20 8:34 amReply to this comment

    @ql: 谢谢,已更正。

  18. 18 bones7456 Commented @ 2008-08-20 9:55 amReply to this comment

    要介绍这个,就得搞个全的…

  19. 19 GunsNRose Commented @ 2008-08-20 10:05 amReply to this comment

    以前学着适应这个,后来还是set -o vi习惯一些,毕竟平时用vim
    之前因为老用 screen跟 ctrl -a 冲突,后来把screen的改成 Ctrl - `
    偶尔在其他地方 用emacs模式

  20. 20 giv Commented @ 2008-08-20 10:47 amReply to this comment

    ms就是因为readline没有移植到native win32, 所以bash, lftp现在都没有native win32的移植?

  21. 21 hmy Commented @ 2008-08-20 10:54 amReply to this comment

    @liufeng
    其实越是基础的东西,越容易被忽视。所以还是推荐一下
    另外有个getent工具,如果不是程序员,可能很多人也不知道是干什么用的吧。

  22. 22 iveney Commented @ 2008-08-20 11:20 amReply to this comment

    @hmy
    赞,原来还有这么方便的工具。

  23. 23 f.s.vivian Commented @ 2008-08-20 12:11 pmReply to this comment

    快捷键还真的忽视了。。。恩,学习!

  24. 24 shelling Commented @ 2008-08-20 3:07 pmReply to this comment

    快速鍵是仿 emacs 的
    並應該不是 readline 內建的
    bash 也有 vi 編輯模式
    只是預設是 emacs 模式而已

  25. 25 mysurface Commented @ 2008-08-22 8:42 amReply to this comment

    你也可以让你编写的程式支持readline,只要你有 libreadline 和 libncurses。http://cc.byexamples.com/20080616/gnu-readline-implement-custom-auto-complete/

  26. 26 cssh:cluster 管理工具 (ssh) | 搜我收藏 Pingbacked @ 2008-08-22 11:49 amReply to this comment

    [...] 如上图所示,同时控制了 6 个机器,右上那个小的窗口就是命令输入窗口,输入窗口的命令就会同时在 6 个机器上执行。这个输入窗口支持 readline。 [...]