2025-12-15-001
srijan.ch·1d
📝Shell Parsing
Preview
Report Post

Srijan Choudhary

15 Dec 2025 06:55 AM 15 December 2025 06:56 AM

A small elisp snippet that I found useful. I often switch between terminals and Emacs, and they have slightly different behaviors for C-w. This makes it behave the same in Emacs as it does in bash/zsh/fish etc - deletes the last word. It retains the kill-region behavior if a region is actually selected.

(defun kill-region-or-backward-word ()
"If the region is active and non-empty, call `kill-region'.
Otherwise, call `backward-kill-word'."
(interactive)
(call-interactively
(if (use-region-p) 'kill-region 'backward-kill-word)))
(global-set-key (kbd "C-w") 'kill-region-or-backward-word)

Ref: [https://stackoverflow.com/questions/13844453/how-do-i-make-c-w-behave-the-…

Similar Posts

Loading similar posts...