GVIM on Windows auto insert newline when editing txt file

This is a strange problem, on Windows and in GVIM, whenever I'm editing a txt file, and the line exceed 80 columns, GVIM will do a hard wrap: insert a new line and go to next line, which is irritating. Because I will add new line when needed, not by the editor.

The strange thing is it only happens when the file has a txt extension. Other files don't have this problem.


Execute :set formatoptions or shortcut :set fo, shows that in txt file the value is tcq and in for example java source file is croql

They are a string of letters define how VIM formats text, here is the full list, you can see in VIM by execute :help fo-table

t    Auto-wrap text using textwidth
c    Auto-wrap comments using textwidth, inserting the current comment
    leader automatically.
r    Automatically insert the current comment leader after hitting
    <Enter> in Insert mode.
o    Automatically insert the current comment leader after hitting 'o' or
    'O' in Normal mode.
q    Allow formatting of comments with "gq".
    Note that formatting will not change blank lines or lines containing
    only the comment leader.  A new paragraph starts after such a line,
    or when the comment leader changes.
w    Trailing white space indicates a paragraph continues in the next line.
    A line that ends in a non-white character ends a paragraph.
a    Automatic formatting of paragraphs.  Every time text is inserted or
    deleted the paragraph will be reformatted.  See |auto-format|.
    When the 'c' flag is present this only happens for recognized
n    When formatting text, recognize numbered lists.  This actually uses
    the 'formatlistpat' option, thus any kind of list can be used.  The
    indent of the text after the number is used for the next line.  The
    default is to find a number, optionally followed by '.', ':', ')',
    ']' or '}'.  Note that 'autoindent' must be set too.  Doesn't work
    well together with "2".
    Example: >
        1. the first item
        2. the second item
2    When formatting text, use the indent of the second line of a paragraph
    for the rest of the paragraph, instead of the indent of the first
    line.  This supports paragraphs in which the first line has a
    different indent than the rest.  Note that 'autoindent' must be set
    too.  Example: >
            first line of a paragraph
        second line of the same paragraph
        third line.
<    This also works inside comments, ignoring the comment leader.
v    Vi-compatible auto-wrapping in insert mode: Only break a line at a
    blank that you have entered during the current insert command.  (Note:
    this is not 100% Vi compatible.  Vi has some "unexpected features" or
    bugs in this area.  It uses the screen column instead of the line
b    Like 'v', but only auto-wrap if you enter a blank at or before
    the wrap margin.  If the line was longer than 'textwidth' when you
    started the insert, or you do not enter a blank in the insert before
    reaching 'textwidth', Vim does not perform auto-wrapping.
l    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.
m    Also break at a multi-byte character above 255.  This is useful for
    Asian text where every character is a word on its own.
M    When joining lines, don't insert a space before or after a multi-byte
    character.  Overrules the 'B' flag.
B    When joining lines, don't insert a space between two multi-byte
    characters.  Overruled by the 'M' flag.
1    Don't break a line after a one-letter word.  It's broken before it
    instead (if possible).
j    Where it makes sense, remove a comment leader when joining lines.  For
    example, joining:
        int i;   // the index ~
                 // in the list ~
        int i;   // the index in the list ~

Looks like the cuase of the problem is the letter t, it will auto wrap the text by text-width.

The reason is the tcq is the default value, but other type of files can change this value,here is how java file do it, in vim74\ftplugin\java.vim, this directory contains all Vim filetype plugin file, but it doesn't include txt file type:

setlocal formatoptions-=t formatoptions+=croql

Now what I need is apply the same change to txt file, the following line solves my problem:

Add this line to _vimrc:

autocmd BufRead,BufNewFile   *.txt setlocal formatoptions-=t formatoptions+=croql