0

I know I can delete backward one word at a time, but many times I just want to change part of a path. Is there a command in emacs and therefore keyboard command in bash to delete backward just until a slash?

alt+w does one word at a time: How can I delete a word backward at the command line (bash and zsh)?

alchemy
  • 597

3 Answers3

0

Well, I realized a simple solution.. basically to use ctrl+left-arrow to skip back to the point I want to change. Then press ctrl+k to delete forward.

(just an aside, ctrl+left-arrow doesnt always work on some terminals, GCP remote ssh shell for example, and I wonder why)

alchemy
  • 597
  • Depending on the terminal emulation used, the left-arrow-key may be sent as some escape sequence or as cltr-H (backspace), causing problems when trying to send ctrl-ctrl-H – Philippos Mar 30 '22 at 09:52
0

If you are in vi mode (set -o vi), you do Esc to return to normal mode, then db (delete to beginning).

If you are in emacs mode (typically the default), you can do CtrlR for backwards search, then / to search for the slash, finally altd to delete forward.

Philippos
  • 13,453
  • interesting.. good to know that Ctrl+R searches also searches the current line when there is one. – alchemy Mar 31 '22 at 23:25
0

From what I understand, you want to properly configure GNU-readline (which handles text edition at GNU-bash's prompt)

In Bash, you can type

bind '"\ew": backward-kill-word'

Then test.

To make this permanent, as a user, you can edit ~/.inputrc, which takes priority over the system config in /etc/inputrc. You can $include /etc/inputrc in ~/.inputrc to inherit from it.

You want to have this line:

"\ew": backward-kill-word

This often defaults to unix-word-rubout, or even a shell or bash prefixed macro, which takes only white space as a delimiter. But backward-kill-word will take anything that is "not a letter nor a digit".

Refer to man 3 readline for full documentation.

AdminBee
  • 22,803