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
    Are you using Emacs on a terminal? – Malabarba Jun 16 '15 at 5:33
  • No, I am using the stand alone emacs. – godblessfq Jun 25 '15 at 19:57
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)
  • On my computer, when I check the binding of shift key + <backspace> is <backspace>. – godblessfq Jun 26 '15 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, privacy policy and cookie policy

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