I want to achieve functionality similar to c + a + w
or d + a + w
in vim
In terminal we have Ctrl + w
for delete a word in the left and Alt + Backspace
from the right But I was not able to find a command to achieve this functionality
I want to achieve functionality similar to c + a + w
or d + a + w
in vim
In terminal we have Ctrl + w
for delete a word in the left and Alt + Backspace
from the right But I was not able to find a command to achieve this functionality
If you are using a shell which uses readline(3) as bash, you have either to combine two shortcuts:Alt-dAlt-Backspace
Or you define a key which is not already in use, see the output of the command command bind -sp
. The latter is already answered in bash readline inputrc: bind key to a sequence of multiple commands.
zsh's line editor supports all of vim
's [cd][ai][wW]
(even an extra [cd][ia]a
as a bonus) out of the box when in vi
mode (entered with bindkey -v
like in tcsh or set -o vi
like in ksh
).
See info zsh 'Text Objects'
for details.
$ bindkey -M viopp
"^[" vi-cmd-mode
"^[OA" up-line
"^[OB" down-line
"^[[A" up-line
"^[[B" down-line
"aW" select-a-blank-word
"aa" select-a-shell-word
"aw" select-a-word
"iW" select-in-blank-word
"ia" select-in-shell-word
"iw" select-in-word
"j" down-line
"k" up-line
As the documentation says, you could also bind those in emacs
mode. Like:
bindkey '^W' select-a-word
Though in emacs
mode, you may prefer doing it the emacs way and navigate word-wise with Alt+b/f and delete the words forward or backward with Alt+d / Ctrl+w¹ and maybe decide on the definition of word dynamically with select-word-style
and co..
See also Zsh zle shift selection on the "stackoverflow" sister site for navigation and selection (including word-wise) à la Microsoft Windows with the arrow keys if your keyboard has those.
¹ Well, technically that ^W
is not emacs
-like, more like the one in the terminal line discipline.