114

I'm editing a network protocol frame stored in a file in Unix (\n newlines). I need to insert the carriage return character (U+000D also known as \r or ^M). When I try to paste it from the clipboard ("+p) or type it using Ctrl+Shift+u-000d, the linefeed is inserted (U+000A).

What is the right way to do it?

Henke
  • 4,445
  • 3
  • 31
  • 44
Andrey Vlasovskikh
  • 16,489
  • 7
  • 44
  • 62

1 Answers1

186

Type: ctrl-v ctrl-m

On Windows Use: ctrl-q ctrl-m

Ctrl-V tells vi that the next character typed should be inserted literally and ctrl-m is the keystroke for a carriage return.

Hulk1991
  • 3,079
  • 13
  • 31
  • 46
R Samuel Klatchko
  • 74,869
  • 16
  • 134
  • 187
  • 10
    Thanks, this works for me. The help can be found using `:help ins-special-keys`. – Andrey Vlasovskikh Oct 18 '09 at 17:32
  • 2
    If you're using the default Windows installation then replace CTRL+V by CTRL+Q since CTRL+V is remmaped to 'paste'. – Cyber Oliveira Oct 20 '09 at 15:12
  • 11
    After much headbanging I'm adding this here even though it's an old question: to insert a literal CR character from a :s command, you must precede it with a backslash or else vim (7.1.314) will convert it to the end of line character appropriate for your fileformat setting. ie enter `:s/.../\^V^M/g`. – DerfK Mar 09 '11 at 23:17
  • 9
    What about `Ctrl+V` followed by `Enter`? I notice that also inserts `^M` into the text – Braden Best Apr 10 '13 at 02:09
  • 2
    Note that this also works for ESC as well: first, go into INSERT mode (i), then Ctrl+V ESC, and you've got yourself an ESC character. – Christopher Schultz Mar 11 '15 at 15:10
  • I wanted to write ^R in vim, however could not get it to work until I tried this in insert mode – serup Jan 20 '17 at 07:18