kill-word
and backward-kill-word
deletes too much text:
foo(bar)
<point>
Now if I press C-<backspace>
:
foo(<point>
What I want is:
foo(bar)<point>
after pressing C-<backspace>
, just like how the other editors do.
EDIT: Based on the answer from @gigiair, I'm trying to implement the command sequency in elisp, but I'm getting "Wrong number of arguments" when executing the code:
(defun leo/backward-kill-word ()
"Better backward-kill-word."
(interactive)
(set-mark-command)
(backward-sexp)
(forward-sexp)
(backward-delete-char-untabify))
I'm new to elisp, know nothing about.
vim
does not do that when I useC-<backspace>
either ininsert
or inedit
mode.set-mark-command
takes an argument (see its doc string withC-h f set-mark-command). *BUT* you should *not* use
set-mark-command` (orset-mark
) from lisp: it's supposed to be used interactively. See the doc string ofset-mark
withC-h f set-mark
.backward-delete-char-untabify
also takes an argument, but you probably shouldn't be using that either. Usingdelete-region
(orkill-region
depending on whether you do not or you do want to keep the contents of the region in the kill-ring) as in the answer below is a much better way. But I don't think that the sexp motion commands are appropriate for this problem.