Search code examples
emacsspacemacsevil-mode

Spacemacs evil-insert at start of line? (Emacs Evil Mode)


I finally got this to work, but wanted to know if there was an easier way.

I want to bind a key "U" to put spacemacs into insert-mode, but at the start of the text of the line.

(define-key evil-normal-state-map "u" 'evil-insert)
(define-key evil-normal-state-map "U" (lambda ()
                                        (interactive)
                                        (beginning-of-line-text)
                                        (execute-kbd-macro "u")))

Is there an 'evil command to insert mode at start of line? Or a more elegant way to fire 'evil-insert or run multiple commands?


Solution

  • In evil-mode i executes evil-insert and I executes evil-insert-line.

    So the simplest rebinding would be:

    (define-key evil-normal-state-map "u" 'evil-insert)
    (define-key evil-normal-state-map "U" 'evil-insert-line)
    

    Whenever you want to know which keys run which functions just press C-h k and then the keybinding of choice.