Skip to content

Instantly share code, notes, and snippets.

@noahlt
Created October 23, 2011 07:26
Show Gist options
  • Save noahlt/1306993 to your computer and use it in GitHub Desktop.
Save noahlt/1306993 to your computer and use it in GitHub Desktop.
How do I make emacs' backward-kill-word not kill across line breaks?
(defun noah-backward-kill ()
"Exactly like backward-kill-word, except doesn't kill across line breaks."
(interactive)
(let ((init-pos (point))
(line-begin (line-beginning-position))
(word-begin (backward-word-position)))
(if (= (point) line-begin)
(backward-delete-char 1)
(if (< word-begin line-begin)
(kill-region line-begin init-pos)
(backward-kill-word 1)))))
(global-set-key (kbd "C-w") 'noah-backward-kill)

Use my version of backward-kill-word instead. Add it to your .emacs file.

["emacs","lisp","kill","emacslisp"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment