8

My system is debian wheezy, I tried to do the following

(global-set-key (kbd "S-<backspace>") 'evil-shift-left-line)
(global-set-key (kbd "<S-backspace>") 'evil-shift-left-line)
(define-key global-map [S-backspace] 'evil-shift-left-line)

What I want is in evil insert mode, I can delete one tab width forward instead of press backspace 4 times. The keybinding works on my laptop, but doen't work on my desktop. I check the binding for evil-shift-left-line, it has changed but doesn't work, and help on "shift-backspace" only shows "backspace". However, shift do has effect on "backspace", "shift-backspace" delete the previous word instead of character.

When I insert "shift-backspace" after "C-q", it has the same notation "^?" as "backspace" on my desktop, while on my laptop the former is "^@".

Any ideas on why it doesn't work on my desktop? Thank you for your help!

This question may be related to this one: Shift+Up isn't recognized by Emacs in a terminal

2
  • 2
    Are you using Emacs on a terminal?
    – Malabarba
    Jun 16, 2015 at 5:33
  • No, I am using the stand alone emacs.
    – godblessfq
    Jun 25, 2015 at 19:57

3 Answers 3

6

Interestingly, you can try binding the deletechar pseudo key.

When I check the binding of backspace on my machine with C-h k [backspace], I get:

DEL (translated from <backspace>) runs the command... (blah blah blah)

When I check the binding of shift + backspace on my machine with C-h k S-[backspace], I get:

<deletechar> (translated from <delete>) runs the command... (blah blah blah)

The following therefore works on my machine:

(global-set-key [deletechar] #'evil-shift-left-line)
1
  • On my computer, when I check the binding of shift key + <backspace> is <backspace>.
    – godblessfq
    Jun 26, 2015 at 13:18
2

I have this in my setup:

(define-key global-map [(shift backspace)] 'backward-delete-whitespace)
(define-key global-map [(shift delete)] 'forward-delete-whitespace)

to make shift+backspace / shift+delete kill all whitespace.


And just in case someone would need these functions, here they are:

(defun backward-delete-whitespace ()
  (interactive)
  (let ((p (point)))
    (re-search-backward "[^ \t\n]+" nil t)
    (forward-char)
    (delete-region p (point))))

(defun forward-delete-whitespace ()
  (interactive)
  (re-search-forward "[ \t\n]+" nil t)
  (replace-match "" nil nil))
1

I am now happy with this setting.

(defun my/backspace()
  (interactive)
  (if (string-match "[^[:space:]]+"
                    (buffer-substring-no-properties
     (line-beginning-position) (point))) ;; return nil no match
      (backward-kill-word 1)(evil-shift-left-line)))

Your Answer

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

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