2

I can not wrap my head finding a solution for this simple editing task in Readline. I just want to kill the characters forward until the end of a Big word, that is, (more or less) until the next space character (dE in vim).

Specially, when hitting a key sequence,

> 2234I567.890 32345678

would become

> 2234I 32345678

where the cursor position is indicated by I.

Here are what I've tried to add in ~/.inputrc to make it happen.

  1. First attempt:

    "\eF": vi-fWord
    "\eD": "\eF\C-w"
    

This does kill forward for a Big word, but it works incorrectly if the cursor is placed in word. In that case, the whole word is killed.

  1. Second attempt:

    "\eF": vi-fWord
    "\C-x1": kill-region
    "\eD": "\C-@\eF\C-x1 "
    

This should have worked, shouldn't it? At least it works if I manually kick the complete \C-@\eF\C-x1 key sequence myself on the commandline. However it was weird that nothing happened when I kicked \eD key sequence.

  1. I also thought about using vi mode command vi-delete-to and the likes, but not sure how to do it due to the complete lack of documentation relating to Readline vi mode.

So I'm here to seek help.

1

OK, I have got it work finally.

It turns out that I just have to remap set-mark function to another key sequence (say, \C-x2) and replace the default \C-@ with this new mapping. Then everything works just fine.

Maybe it's a bug that \C-@ doesn't function as expected when appearing in RHS of a Readline macro.

The following is my setup that makes Alt + D delete input forward to the next space or big WORD (in vim jargon).

"\C-x0": vi-eWord
"\C-x1": kill-region
"\C-x2": set-mark
"\eF": "\C-x0\C-f"
"\eD": "\C-x2\eF\C-x1"

Because we didn't use shell-specific Readline function such as shell-forward-word, the key binding works in all applications that utilize Readline library, for example, bash, (i)python, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.