On Windows 8, I want to edit with Vim (v7.4), files that were originally created with Windows Notepad. However, when I begin to write, Vim/gVim spontaneously breaks lines into smaller ones by inserting CRLF at arbitrary points.

For example, given the following single line file:

Picture of original line

If I append a single character to this line, Vim immediately breaks it into four lines:

Picture of modified line

This does not occur if the file was originally created by Vim. And I have certainly never seen this behavior in Linux. It occurs only on Windows, when editing non-Vim-created files.

Why does Vim break lines in this way? And how can I prevent it?


The problem is a feature called "Automatic word wrapping" documented here. To disable the insertion of line breaks when adding text to a line, add "l" to the value of option formatoptions.

After doing this, the problem vanished.

  • As noted in this question, the problem occurs only when editing files with the .txt extension (that was my case). In non .txt files, I have never seen this "automatic word wrapping" behavior. Can anybody provide a link to documentation of why this feature affects .txt files only? – ARX Feb 4 '16 at 21:28

Edit -> File Settings -> Toggle Line Wrap or :set wrap!

  • :set wrap! produces a different effect. The long line of text no longer fits in the screen. Besides, the problem persists: when I append a character, the line is immediately broken into smaller lines, as it can bee seen in the screenshots of the question. Vim keeps inserting CRLFs. – ARX Feb 4 '16 at 17:33
  • "The long line of text no longer fits in the screen." -> That's because it's now treated as it actually is. Line wrap was making it "fit the screen" temporarily by adding line breaks. When you edit the document, it makes the temporary line breaks permanent. This sort of behaviour is a side-effect of vi being terminal-based. – Mekki MacAulay Feb 4 '16 at 17:44

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.