Emac's backward-kill-word tends to delete more than I want.
E.g when I press delete multiple times on this:

(key-chord "qf" 'helm-org-in-buffer-headings)   ;heading search. |

I get:

1. (key-chord "qf" 'helm-org-in-buffer-headings)   ;heading|
2. (key-chord "qf" 'helm-org-in-buffer-headings)   ;|
3. (key-chord "qf" 'helm-org-in-buffer-|   <<< too much deletion. 

I expected this in the 3rd step:

3. (key-chord "qf" 'helm-org-in-buffer-headings)|

I want to know: - Is there a philosophy behind deleting more than what's wanted?
- Can I make emac's backward-delete-word more friendly? I.e, remove white spaces but don't kill off 'too' much?

EDIT I don't really know 'what' I want. Maybe make it more like other delet functions like in google-keep or other text editing applications.

In the mean time, lawlist fixed up his custom function which works rather well: enter link description here

  • 2
    This risks being closed as unclear. You do not specify what behavior you want. Specify. backward-kill-word does what it is intended to do. You can define another command to do "what's wanted" and not "kill off 'too' much". But if you want help with that then you might consider actually specifying the behavior you are looking for.
    – Drew
    Commented Apr 12, 2015 at 2:27
  • 1
    Here is a link to my own delete-word function, which you may be interested modifying to suit your needs: stackoverflow.com/a/20456861/2112489 It is not designed to store the deletion into the kill-ring, so I call it delete rather than kill. It has nothing to do with helm or key cord. The behavior (in my opinion) approximates what various word processors have done over the years.
    – lawlist
    Commented Apr 12, 2015 at 2:31
  • @lawlist yah, this is more or less what I was looking for, except that I found the function there doesn't wrap around and doesn't start deleting things if there are trailing white spaces? Commented Apr 12, 2015 at 3:52
  • Emacs philosophy is to always stay one step ahead of the user.So you just don't know yet.
    – politza
    Commented Apr 13, 2015 at 20:03
  • @LeoUfimtsev is there anything you don't like about the solution I provided?
    – user2005
    Commented Apr 14, 2015 at 4:47

1 Answer 1


The behaviour of backward-kill-word depends on the definition of a "word" in the current mode. You can either change this definition and risk breaking stuff or you could modify kill-word.

backward-kill-word is just kill-word with a negative argument; kill-word is kill-region over the region spanned by point and the position after running (forward-word arg). Replacing forward-word temporarily should do the trick.

Here I'm temporarily replacing forward-word with forward-same-syntax to achieve the desired effect in backward-kill-word (and kill-word because I like things to be consistent):

(defun my/kill-word-advice (orig-fun &rest args)
  "Replace forward-word with forward-same-syntax."
  (cl-letf (((symbol-function 'forward-word) #'forward-same-syntax))
    (apply orig-fun args)))
(advice-add 'kill-word :around #'my/kill-word-advice)

Now the behaviour is this:

1. (key-chord "qf" 'helm-org-in-buffer-headings)   ;heading|
2. (key-chord "qf" 'helm-org-in-buffer-headings)   ;|
3. (key-chord "qf" 'helm-org-in-buffer-headings)   |
4. (key-chord "qf" 'helm-org-in-buffer-headings)|
5. (key-chord "qf" 'helm-org-in-buffer-headings|
5. (key-chord "qf" 'helm-org-in-buffer-|
  • 1
    Hello, I tried the above, but when I run backwards kill word, I still get the old behaviour. I'm on Emacs 25.4 with newest org-mode.. Commented Apr 14, 2015 at 15:25
  • @LeoUfimtsev I saw you mention 25.4 somewhere else too. Do you mean 24.5? Or 24.4? Commented Apr 15, 2015 at 21:06
  • Hmm, I think I got muddled up. I meant And maybe a month ago I used, but now I updated. Commented Apr 15, 2015 at 21:12
  • @rekado I can’t get this to work in 24.5.1. Any idea? Executing the advice-add sexp returns nil, is that expected?
    – Lenar Hoyt
    Commented Jun 10, 2015 at 22:08
  • 1
    It may very well be that you first have to eval the original definition of kill-word before the advice is applied :( I don't know why that is. Will ask on the mailing list.
    – user2005
    Commented Jun 11, 2015 at 4:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.