21

I would like to use something like Shift + Enter to create a new line in Vim.

So if | is the cursor, here is what I would like to do:

<%= some.code("in here") | %>

Now, press Shift + Enter (or something similar) and get this as output:

<%= some.code("in here") %>
and my new line here |

Is this possible?

chris
  • 4,890
  • 19
  • 36
DavidVII
  • 1,693
  • 1
  • 19
  • 28

3 Answers3

31

Escape to Normal Mode

There are probably a number of ways to do what you want, but one option is to use CTRL-O to escape to normal mode to insert the line. For example CTRL-O o will open a new line below the current line and place your cursor there in insert mode.

If you want to map this rather than use it as a one-off, you can use an imap to set your mnemonic of choice. For example:

:imap \nn <C-O>o

will create an insert-mode mapping for \nn that will do the same thing.

Todd A. Jacobs
  • 76,463
  • 14
  • 137
  • 188
24

<ESC> o - To open a line below

<ESc> Shift + o - To open a line above.

Vihaan Verma
  • 12,305
  • 19
  • 93
  • 124
12

I use imap <C-o> <esc>o to bind new line on Ctrl+O

wedens
  • 1,724
  • 14
  • 17
  • 10
    I this case you overwrite the default in insert mode which enters in normal mode for one command and switches back. Right? – Alex Shwarc Mar 03 '17 at 13:28