Is there a way to run a regexp-string replace on the current line in the bash?
I find myself rather often in the situation, where I have typed a long commandline and then realize, that I would like to change a word somewhere in the line.
My current approach is to finish the line, press Ctrl+A (to get to the start of the line), insert a # (to comment out the line), press enter and then use the ^oldword^newword syntax (^oldword^newword executes the previous command after substituting oldword by newword).
But there has to be a better (faster) way to achieve this. (The mouse is not possible, since I am in an ssh-sessions most of the time).
Probably there is some emacs-like key-command for this, that I don’t know about.
Edit: I have tried using vi-mode. Something strange happened. Although I am a loving vim-user, I had serious trouble using my beloved bash. All those finger-movements, that have been burned into my subconscious suddenly stopped working. I quickly returned to emacs-mode and considered, giving emacs a try as my favorite editor (although I guess, the same thing might happen again).
Unfortunately, no, there’s not really a better way. If you’re just tired of making the keystrokes, you can use macros to trim them down. Add the following to your
~/.inputrc:Now, in a new bash instance (or after reloading
.inputrcin your current shell by pressingC-x C-r), you can do the following:ls abcxyz).#at the beginning of the line, executes the commented line, and types your first^.xyz^def).It’s not exactly elegant, but I think it’s the best you’re going to get with readline.