【问题标题】:On bash command-line, how to delete all letters before cursor?在 bash 命令行上,如何删除光标前的所有字母?
【发布时间】:2012-09-02 07:21:30
【问题描述】:

在 bash 命令行中,如何删除光标前的所有字母?我知道 Ctrl-k 会删除光标之后的所有内容。

【问题讨论】:

标签: bash command-line


【解决方案1】:

Ctrl-u - Cut everything before the cursor


其他 Bash 快捷方式,

  • Ctrl-a Move cursor to beginning of line
  • Ctrl-e Move cursor to end of line
  • Ctrl-b Move cursor back one word
  • Ctrl-f Move cursor forward one word
  • Ctrl-w Cut the last word
  • Ctrl-k Cut everything after the cursor
  • Ctrl-y Paste the last thing to be cut
  • Ctrl-_ Undo

并通过 bash shell 的手册页发现更多信息:man bash

其他 bash 命令行快捷方式备忘单:http://www.bigsmoke.us/readline/shortcuts

在此处查看文档:http://www.gnu.org/software/bash/manual/bashref.html#Commands-For-Killing

必读:通过 Julia 的漫画了解有关 Bash、Linux 和技术的更多信息:https://twitter.com/b0rk/media

【讨论】:

  • 在我的系统上 ctrl-b 和 ctrl-f 移动一个字符。
  • 关于这些的“官方”文档在哪里?为什么只展示鱼而不展示如何钓鱼?
  • @Problemania 我添加了一个链接。一般来说,man 或 info 页面是一个不错的起点,尝试运行命令 man 后跟您正在使用的 unix 工具的名称(例如 man bash)。
  • 知道什么是 zsh 的 Ctrl+u 等价物吗?
  • 在zsh中,Alt+w清除光标前的所有字符。
【解决方案2】:

zsh中,Alt+w清除光标前的所有字符。

与 bash 相比,这 不会削减它们;它只是删除它们。

这适用于 zsh 的 Emacs 模式(这是默认模式),不适用于 Vi 模式。

【讨论】:

    【解决方案3】:

    热键 Ctrl+U 应该会为您执行此操作。

    【讨论】:

      【解决方案4】:

      Ctrl+x 退格清除光标当前位置之前的所有条目

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-02
        相关资源
        最近更新 更多