How do you produce a CR/LF anywhere in a text document created in linux OS so that it can be copied and pasted into a windows text editor or onto the web and retain the CR/LF to be read and acted upon in a windows OS or on the web? A for instance would be ascii art that requires CR/LF to keep character alignment accurate. Producing ascii art in linux with CR/LF codes that can be utilized in windows or online.

  • 1
    Copy/pasted how? Text document in what context? Are you talking about an interactive editor or are you...well... what are you talking about?
    – mikeserv
    Jun 8, 2015 at 0:58
  • edited for clarity ( I hope )
    – Rocket
    Jun 8, 2015 at 9:53

4 Answers 4


Don't worry about it, use standard Unix/(GNU) Linux tools, and then run unix2dos on your Unix file.


This can easily be done with vim.

If you want to convert all line breaks into CR/LFs in a file,

  1. Open the file in vim (vim file.txt).
  2. Convert the file to DOS format (which means CR/LF line breaks): :e ++ff=dos.
  3. Save and quit (Shift+Z Shift+Q or :wq).

If you simply want to insert a single CR/LF line break,

  1. Open the file in vim (vim file.txt).
  2. Navigate to the line that you want to insert a CR/LF line break after (if you're not familiar with vim, you can just use the up and down arrow keys).
  3. Enter insert mode, appending to the end of the line (Shift+A).
  4. Insert a carriage return character (Ctrl+V Ctrl+M).
  5. Insert a line feed character (Return).
  6. Exit insert mode (Esc).
  7. Save and quit (Shift+Z Shift+Q or :wq).
  • ok for clarification (my fault) I am using linux simple text editor and want the CR and the LF to be stored so that when pasted into a MS text editor or into a web chat the CR and LF are acted upon and transferred to the receiving environment.
    – Rocket
    Jun 8, 2015 at 4:09

Edit: So what you actually want to know is how to convert a file from Unix to Windows line endings. Do it from the command line, not the editor, with the following one-liner. It will work correctly even if you run it on the same file multiple times.

perl -pe 's/\r?\n/\r\n/' unix-file.txt > windows-file.txt

You can view a file with od -c to see its newline characters.

PS. By the way some editors will let you save in DOS format and/or preserve the existing line endings (but who knows what you're using.)

Here's the answer for what you thought you wanted:

If you really want to enter them explicitly, you need to know two things: The control codes for CR and LF, and how your editor or whatever lets you enter literal control codes.

  1. CR is ^M (control+M). LF is ^L (control+L).

  2. Find out how your editor "escapes" the next thing you'll type. In emacs that's control+Q (^Q, or C-q in emacs notation), so you'd type ^Q ^M to enter a CR. A more common escape (e.g. in vim and on the bash prompt) is ^V.

Note also that LF is the end of line, so you'll probably not see it after it's entered. But it's there.


you could try Geany, it's a gui type text editor, and line endings are one of the many things you can edit.

Not the answer you're looking for? Browse other questions tagged .