Bash – Deleting input forward to the next space

bashkeyboard shortcutsreadline

When in terminal I can use Ctrl+w to delete a whole word or IP (. is separator for each octet) when going leftward of prompt. However, if I try Alt+d to go rightward of prompt, terminal recognizes "." in IP for a separator and deletes only one chunk, until the . out of the whole IP.

How can I adjust that so terminal recognizes only blank spaces for separator of word or even better to have another shortcut for different separators: ., =, ,, etc?

It is very similar with maneuvering in terminal with Ctrl+Arrows (left and right) and behavior is similar based on what is set for word separator.

I read that Emacs editor sits behind what terminal uses to have those shortcuts but I could not get to twink it.

I'm trying to accomplish this in Ubuntu 10.

Here:https://askubuntu.com/questions/577433/deleting-input-forward-to-the-next-space is what I was suggested in the other forum for Ubuntu 14.

I tried this:

"So, now, if you want to combine those two keystrokes (Alt+w followed by Ctrl+w) in a new one, you will need to bind a new keystroke (in my example Alt+q) to execute the previous keystrokes as follow:

bind '"\eq": "\ew \C-w"'

Finally, to make these changes permanently, all you have to do is to add the following lines to your ~/.inputrc file (if you don't have it, then create it):

"\ew": vi-forward-bigword
"\eq": "\ew \C-w" 

but I get this as result:

When added that, Alt+w still does not work, and Ctrl + and error does not work any more. Terminal outputs ;5D and ;5C when those are used to move from word to word…

What is the difference between the two versions?

Best Answer

If you're an Emacs user, my answer probably isn't something you'll want to use, but it should still be noted on this page so here it is:

You can use vi keybindings in a bash shell very easily. Type set -o vi. Add it to your .bashrc if you like the results.

The answer to your specific question, delete forward to the next space, is accomplished with dt<Space> (delete till space) or just dE (delete to end of space-delimited Word).

Standard vi keybindings are used—the main thing to get used to (if you're a vi user already) is that you'll be in insert mode by default. So to use a Normal-mode command such as the above, type <Esc> first. Alternatively, you can hold down the Alt key while typing the first letter of your command. For instance, k is the vi command to go up one line, so <Alt>k can be used just like the up arrow—to go back one command in your history.

Related Question