Equivalent of vi's cw (change word) command in emacs (for bash, actually)

OS: Red Hat/Oracle Linux 7.x, 8.x

If I am not mistaken, by default, Linux's bash command line's editing mode is emacs.

Imagine, in bash command line, I typed a command like below with arguments.
Then, I realize, I made a mistake and I want to replace the word "database" with the word "service".
In vi/vim world, I could just move the cursor the beginning of the word "database" and press ESC to go to command mode and then type cw which will replace the word "database" and I can just type "service".

$ srvctl status database -db CDB_25P

How can I do it in emacs ? Or whichever trick you follow to replace an entire word in bash command line.

you could use M-d to delete the word under the cursor then type the new one

if you are at the end of the line ... M-4 then M-b should place you at the start of the word database (move back 4 words)

(M == escape key)

2 Likes

you could change your command editing mode to vi : in shell: set -o vi.

3 Likes

@Francois , please give feedback on any solution you found/used, the community benefits from knowledge gained and shared.

thks.

@Francois, thks for the confirmation.