How to clear portion of what is typed into the prompt while working on Linux and using C-shell

command linecshline-editor

I am working in Linux and C-shell. Often times I would require to change some portion of what is there already in the prompt that I obtain from reverse searching through the history command by use of CTRL+R. I do not want to use the Backspace for doing this. I have looked at this question on superuser.com which was specifically for bash.
This answer says to use CTRL+U which would clear out everything before the current cursor position. But this is clearing out everything for me even though I have hit a few backspaces and now am at the middle of the text in the prompt. Is there a C-shell specific way of achieving the same in Linux?

Best Answer

In tcsh (which I suppose is what you're calling "C-Shell" if you're not totally masochist) in emacs mode (usually the default), you can use Ctrl-W. That's the kill-region widget which deletes between the mark (set with Ctrl-Space but defaults to the beginning of the line) and the cursor.

In that regard, its behaviour is closer to emacs' than with bash(readline)/ksh/zsh emacs mode, but departs from the terminal driver embedded line editor (in canonical mode), where Ctrl-W deletes the previous word (werase, also in vi). That time it chose emacs over usual terminal behaviour but not in the case of Ctrl-U where in emacs it's the universal argument while it's the kill-line character in the terminal.

If you'd rather Ctrl-U delete to the beginning of the line, you can also do:

bindkey '^U' backward-kill-line

En vi mode, Esc to go to command mode, and d0 to delete to the beginning of the line (or c0 if you want to change instead of deleting that).

Related Question