can Bash be configured to search string on the cur

2019-07-24 18:54发布

问题:

For fast locating positions when using the command line(Yes, I'm an Emacs fan). After viewing Bash' man, I can't find such tips. Does it need to modify readline's source code to support this?

Thank you very much!!

回答1:

I don't know of a way to do it directly in the command line, but bash does support a keypress that will open the command line in your editor of choice. From the bash manpage:

   edit-and-execute-command (C-xC-e)
          Invoke  an  editor  on the current command line, and execute the
          result as shell commands.   Bash  attempts  to  invoke  $FCEDIT,
          $EDITOR, and emacs as the editor, in that order.

So hitting CTRL-x CTRL-e in emacs bindings mode (the default) or ESC v in vi bindings mode (set -o vi for that) will open the existing command line in the editor specified by the environment variables mentioned above. You can edit the command line, and once you save and quit the editor the command will be executed.



回答2:

CTRL-r (reverse-i-search) will allow you to search the current line as well as anything in your history.

If you want to jump back a couple of arguments, you can hit space, then CTRL-r again to "find again". Escape will break out of it with the cursor at the last search result.



标签: bash readline