With the textwidth option set the text written can be wrapped when we leave insert mode. If I type a line longer than my textwidth value then it will go on a new line.

e.g. with set textwidth=5 and set linebreak :

1 2 3 [4]

1 2 3

lorem ipsum dolor[Esc]


[X] means: I press X where [] is.

So when entering a line of number spearated by space, at the moment I enter the 6th character (in this case the number 4) the line break.

But when I enter a sentence the line doesn't break until I quit insert mode.

Do you know what I can try/set ?

  • 1
    This is not how Vim behaves for me (and I can't recall ever seeing this behaviour). Either something in the vimrc, or the filetype you're using is causing this. Aug 6, 2015 at 14:58
  • Do you know what options I can see to 'debug' this ?
    – nobe4
    Aug 6, 2015 at 14:59
  • 1
    You can try the steps in How do I debug my vimrc file? Aug 6, 2015 at 14:59
  • great, I'll update my post if I get something new, thanks
    – nobe4
    Aug 6, 2015 at 15:00
  • Maybe it has something to see with your formatoptions? What's the result of set fo? on your system?
    – statox
    Aug 7, 2015 at 8:06

2 Answers 2


So as we troubleshooted in the comments the problem came from the formatoption value.

According to :h formatoptions :

This is a sequence of letters which describes how automatic formatting is to be done.

Your settings contained the letter l which according to :h fo-table does the following:

Long lines are not broken in insert mode: When a line was longer than 'textwidth' when the insert command started, Vim does not automatically format it.

So the solution is to use the following command set fo-=l. Still according to the doc it is better to use the += and -= features options of set to avoid conflicts with tags added later.

Another important point is how these tags are set: a lot of filetypes set those tags automatically. For example in [path_to_vim_installation]/vim74/ftplugin/c.vim you can read:

" Set 'formatoptions' to break comment lines but not other lines,
" and insert the comment leader when hitting <CR> or using "o".
setlocal fo-=t fo+=croql

A solution is to override those behavior in your .vimrc for the filetypes that you want.

  • In this case, lorem ipsum dolor[Esc], the line was not longer than textwidth, when the insert command started (it had length 0), so why doesn't vim format it?
    – Shuzheng
    May 31, 2021 at 14:26

Check that your formatoptions contain at least the letters 't' and 'c'.

Make sure paste mode is not set, otherwise all insert mode mappings and formatting is disabled. You can tell is paste mode is set if the -- INSERT (paste) -- prompt appears at the when in insert mode rather than just -- INSERT --. Paste mode can be disabled with :set nopaste.

Otherwise try running Vim with the command vim -u NONE and see if the problem still occurs, this fixes the problem it is an issue with your vimrc file or a plugin.

  • I don't think that formatoptions and paste mode disable insert mode mappings, or I'd be interested to see the relevant documentation.
    – statox
    Aug 7, 2015 at 8:32
  • Only paste mode disables mappings while it is on. Sorry if my writing was unclear.
    – user2283
    Aug 7, 2015 at 8:38
  • For paste - :h 'paste': "[...] When the 'paste' option is switched on (also when it was already on): - mapping in Insert mode and Command-line mode is disabled [...]"
    – VanLaser
    Aug 7, 2015 at 8:38
  • @ZeroKelvinKeyboard: No problem maybe it my reading which was unclear ;-) And thanks @ VanLaser for the doc!
    – statox
    Aug 7, 2015 at 8:42
  • @statox -you're welcome :) And I only found out about it while dealing with undo: vi.stackexchange.com/a/3865/1800 (in comments)
    – VanLaser
    Aug 7, 2015 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.