In Spacemacs, how do I insert a newline, without entering insert mode?
Asked Answered
B

3

9

In Vim, you can bind Enter key to insert a newline without entering insert mode. how can you do this in Spacemacs.

Or how to remap keys in general in Spacemacs?

Brownie answered 28/1, 2016 at 2:35 Comment(0)
H
10

You can use:

(define-key evil-normal-state-map (kbd "RET") 'spacemacs/evil-insert-line-below)

to insert a line below and stay at the same position, or

(define-key evil-normal-state-map (kbd "RET")
  (lambda ()
    (interactive)
    (call-interactively 'spacemacs/evil-insert-line-below)
    (evil-next-line)))

to insert a line below and go to the new line.

Hamblin answered 29/1, 2016 at 10:15 Comment(1)
Add (call-interactively 'evil-insert-state) to get into insert mode after adding a new lineCockrell
B
17

In Spacemacs, it is also possible to insert a new line while remaining in normal state with the wildly useful command spacemacs/evil-insert-line-below.

It is bound to SPC i j in Vim mode and M-m i j in Emacs mode.

Preceding that command with a numerical argument will insert more than one new line, e.g. 4 SPC i j will insert four new lines.

Bordy answered 1/11, 2016 at 21:12 Comment(1)
sweet. any way to make the cursor move to the new line though?Brownie
H
10

You can use:

(define-key evil-normal-state-map (kbd "RET") 'spacemacs/evil-insert-line-below)

to insert a line below and stay at the same position, or

(define-key evil-normal-state-map (kbd "RET")
  (lambda ()
    (interactive)
    (call-interactively 'spacemacs/evil-insert-line-below)
    (evil-next-line)))

to insert a line below and go to the new line.

Hamblin answered 29/1, 2016 at 10:15 Comment(1)
Add (call-interactively 'evil-insert-state) to get into insert mode after adding a new lineCockrell
B
4

I usually use ]SPC to append a new line below. It is equivalent to SPCij.

Also you can add one line above by [SPC.

Bayberry answered 18/3, 2019 at 8:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.