Ctrl+W in the mac terminal to delete a word (deletes from where the cursor is at to the beginning of the word)
How do I do the opposite - deletes from where the cursor is to the end of the word?
This depends on your shell and its active command line editing mode.
For a shell with Emacs command line editing mode (
set -o emacs in some shells), use Alt+D (this doesn't work on macOS for whatever reason, but prints the character
∂, use Escd instead).
For a shell with Vi command line editing mode (
set -o vi in some shells), use Escdw (this does work on macOS as well).
For the tty line discipline,
^W deletes the previous white-space delimited word.
vi editor in insert mode,
^W deletes backward to the start of the first sequence of alnums or non-alnums (on
foo-+-bar.. baz, it first deletes
^W deletes from the cursor position to the mark (the one you set with Ctrl+Space).
Some line editors like
readline (used by
zle (used by
pdksh's when in
vi mode, behave like
vi in that regard and when in
emacs mode behave like the tty line discipline (not
libedit (used by BSD shells or (optionally)
emacs mode, behave like
^W deletes to the mark (initially at the beginning of the buffer).
For deleting a word forward, in the
vi editor, you'd do it in command (normal) mode with
dw to delete to the beginning of the next sequence of alnums or non-alnums (or the end of the line) and
dW to delete to the next sequence of non-blanks (the pendant of the
^W of the tty line discipline).
emacs line editor, Meta-D would delete to the end of the next sequence of alnum characters. The word motion operators (Meta-B, Meta-F) behave similarly.
command line editors, when in
vi mode, behave like
vi, but in
emacs mode, you have two main schools: the
tcsh school and the
ksh school (
yash) behaves mostly like
fish's behaviour is slightly different in how it treats non-alnum, non-whitespace characters in both
tcsh school (
zsh), word motions are based on whitespace-delimited words so are consistent with the tty line discipline's
^W in that regard.
zsh, the behaviour is customizable with different word styles for all the word motion widgets.
readline, you can get the
tcsh school (and have Meta-D delete the same kind of word as Ctrl-W does) by adding to your
set keymap vi-move "\e[EMACS~": emacs-editing-mode set keymap emacs "\e[VI~": vi-movement-mode "\ed": "\e[VI~dW\e[EMACS~" "\ef": vi-fWord "\eb": vi-bWord
Or on the other hand, align
^W to the other word motion widgets (behave like Meta-Backscape) with:
set keymap emacs "\C-W": backward-kill-word
As to what the Meta key is, see there.
In Linux try
Ctrl+k to delete from where the cursor is to the end of the word.
There are few other shortcuts listed below(working in Linux):
Ctrl+e-> Takes cursor at the end of the word.
Ctrl+t-> Inter-change the position of the alphabets.
Ctrl+y-> adds postfix "hh" to current word.
Ctrl+u-> Deletes the whole line.
Ctrl+o-> Works same as Enter key.
Ctrl+p-> Works same as up arrow button.
Ctrl+a-> Brings cursor to the starting position of the command.
Ctrl+d-> Closes terminal.
Ctrl+f-> Moves cursor forward by one Character.
Ctrl+h-> Works same as Backspace key.
Ctrl+j-> Works same as Enter key.
Ctrl+m-> Works same as Enter key.
Ctrl+b-> Works same as Right-arrow key. 14
Ctrl+4-> Deletes the word