简体   繁体   English

如何在bash终端中选择行

[英]How do I select the line in bash terminal

Is it possible to select part of a string in the bash terminal and delete it at once, rather than navigating to a point in the command and backspacing it all?? 是否有可能在bash终端中选择一部分字符串并立即将其删除,而不是导航到命令中的某个点并对其全部退格?

thanks! 谢谢!

I'm not 100% sure I understand your question. 我不确定100%知道您的问题。

If you are at the interactive command line: 如果您在交互式命令行中:

  • ctrl-u : Deletes everything to the left of your cursor ctrl-u :删除光标左侧的所有内容
  • ctrl-k : Deletes everything to the right of your cursor ctrl-k :删除光标右边的所有内容

I'm using emacs bindings and my favourite command line shortcuts, which were not included in the previously linked tutorial, are the following: 我使用的是emacs绑定和我最喜欢的命令行快捷方式,它们是以前链接的教程中未包含的,它们是:

^W     - delete last word
meta-b - move cursor back one word
^R     - find a previously used command
!$     - last attribute of the last command
!!     - last command

You can also manipulate the history with regexps, although that could quickly get quite messy. 您也可以使用正则表达式来处理历史记录,尽管那样很快会变得很混乱。 See "man zshexpn" for reference, mostly the same regexp syntax works for bash also. 请参阅“ man zshexpn”以获取参考,大多数相同的regexp语法也适用于bash。

Example: 例:

1) If you execute the following command: 1)如果执行以下命令:

  echo first second third fourth fifth 

2) Then you could execute the same command and remove "first" by: 2)然后,您可以执行相同的命令并通过以下方式删除“ first”:

  !!:s/first// 

If this was not what you were after, please clarify on your question! 如果这不是您想要的,请澄清您的问题! :) :)

See this . 看到这个 Alternatively, set -o vi to have vim-like key bindings. 或者, set -o vi为具有类似于vim的键绑定。

Note that the list given in the link is not full. 请注意,链接中给出的列表不完整。 You might read man bash for a good reference. 您可以阅读man bash作为参考。 Usually, ALT-x might be replaced by ESC, x if you run bash inside a terminal that uses Alt-letter shortcuts for windowing system. 通常,如果您在使用Alt-letter快捷方式创建窗口的终端中运行bash,则ALT-x可能会被ESC代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM