evil-open-below for smartparens
There’s an vim/evil command that I use often and is named evil-open-below
. It’s bound to o
in normal state. What it does it starts a new line below the current one, moves the point at the beginning of it and switches to the insert state. Really simple and really useful. Often when writing lisp I wanted to open the new line but stay inside the current expression. Using smartparens it was quite easy to achieve what I wanted. Look at this:
(defun sp-open-below ()
(interactive)
(sp-end-of-sexp)
(newline-and-indent)
(evil-insert-state))
Also it’s a good idea to define it as an evil command so you can use the dot for repeating it:
(evil-define-command sp-open-below-command ()
:repeat t
(sp-open-below))
And bind it to “M-o”:
(evil-define-key 'normal smartparens-mode-map
(kbd "M-o") #'sp-open-line-below-sexp-command)
The command in action: