:normal! )i<CR> will go to the start of the next sentence and insert the actual characters <CR>.

How can I modify this to insert a line break instead?

(I've also tried \n and \r instead of <CR>, and escaping them like \\r, but in every case, what's inserted is the characters themselves.)

  • 7
    Instead of typing <, C, R, >, press <C-v> then <return> to insert a literal ^M. – romainl May 21 '16 at 11:12
  • 4
    Other way to do is with 'o'. :normal! )o. It automatically start inserting at next line. – SibiCoder May 21 '16 at 11:21

To expand <cr> as a newline, you need to use commands which evaluate it as an expression. In this case, you need execute:

:exe 'normal!' ")i\<cr>"

Or, as romainl says, you enter a literal newline using CtrlV Enter.

Note the \ before <cr>. From :h string:

string                                  string String expr-string E114
"string"                string constant         expr-quote

Note that double quotes are used.

A string constant accepts these special characters:
\...    three-digit octal number (e.g., "\316")
\n      newline <NL>
\r      return <CR>
\<xxx>  Special key named "xxx".  e.g. "\<C-W>" for CTRL-W.  This is for use
        in mappings, the 0x80 byte is escaped.  Don't use <Char-xxxx> to get a
        utf-8 character, use \uxxxx as mentioned above.

So, with :exe, you can also use \r:

:exe 'normal!' ")i\r"
| improve this answer | |
  • Nice, does that mean we can escape arbitrary key with execute? – nobe4 May 21 '16 at 17:00
  • 1
    @nobe4 Only those listed in :h keycodes, I think (which is a lot of keys, but not all of them) – muru May 21 '16 at 17:02

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.