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...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help