In spacemacs Ctrl-a is being used to move to the beginning of the line. I'm more used to 0 to move to the beginning of the line and $ to the end, which works in spacemacs. Ctrl-a increases numbers in vim and I'd like to use that key in spacemacs too. How can I do so? I tried to unbind the keys with the following in my .spacemacs:

(define-key org-mode-map (kbd "C-a") nil)
(define-key global-map (kbd "C-a") nil)

Now the key doesn't move to the beginning of the line, but it also doesn't increment numbers, it does nothing. When I use it, it simply shows "C-a is undefined".


The package evil-numbers does exactly what you need.

| improve this answer | |
  • Why isn't this part of evil-mode? – ideasman42 Jan 14 '19 at 1:56
  • No idea, but it doesn't help that both C-a and C-x are bound by default in Emacs. – wasamasa Jan 14 '19 at 7:14

I've stumbled upon the same issue of preference and as suggested before, evil-numbers is the package for that. But while trying to set it up, it was surprising that evil-numbers is already in spacemacs, just missing the keybinds.

To activate, just add

(define-key evil-normal-state-map (kbd "C-a") 'evil-numbers/inc-at-pt)
(define-key evil-visual-state-map (kbd "C-a") 'evil-numbers/inc-at-pt)
(define-key evil-normal-state-map (kbd "C-x") 'evil-numbers/dec-at-pt)
(define-key evil-visual-state-map (kbd "C-x") 'evil-numbers/dec-at-pt)

to your user-init and it will work with Ctrl+a and Ctrl+x combinations. (taken from the package's *.el file in git)

I don't get any conflicts with previous keybinds, i guess emacs redefines them, not overlays. (?)

| improve this answer | |
  • 2
    Can you edit your question to have appropriate keybindings rather than telling to change them? – user12563 Jan 13 '19 at 23:43
  • Ofcourse i can :) – Alvin Jan 14 '19 at 0:36

Emacs doesn't have a built-in function to increment numbers, so let's grab this one from EmacsWiki:

(defun increment-number-at-point ()
  (skip-chars-backward "0-9")
  (or (looking-at "[0-9]+")
      (error "No number at point"))
  (replace-match (number-to-string (1+ (string-to-number (match-string 0))))))

Now we can bind C-a to that function:

(global-set-key (kbd "C-a") 'increment-number-at-point)
| improve this answer | |

There are different bindings for this functionality in spacemacs.
You can increment with Space n + or Space n = and decrement with Space n -.

For more information take a look at the official documentation: https://github.com/syl20bnr/spacemacs/blob/master/doc/DOCUMENTATION.org#increasedecrease-numbers Or this issue on GitHub: https://github.com/syl20bnr/spacemacs/issues/9895

(On the develop branch these currently open a transient state in which you can further increment or decrement the values.)

| improve this answer | |

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.