My formatoptions include cro.I have a filetype (Stata .do files) in which the comment character is *. Anything after this character is considered a comment line.In insert mode *<CR>* leads to** <cursor>However **<CR> leads to**<cursor>My desired behavior, which seems to work in most other filetypes in my configuration, is that **<CR> leads to***<cursor>What's wrong with this filetype and how can I fix it?Another filetype example I found with similar behavior is Python. There if I do #<CR># I get##<cursor>But if I do ##<CR> I get##<cursor>Instead of what I would expect, which is###<cursor>This seems to be the same behavior as with the Stata files except that in the Stata files vim also inserts a space after the *. In Python it doesn't add the space but still doesn't recognize ## as being a comment line.
Automatic comment leader not inserted on some file types
comments
You might have to set a custom comments. For me, comments in a Python file is:comments=b:#,fb:-With some experimenting, I found that, for Vim to insert # after lines with ##, I needed to use a three-piece comment (or part of one, anyway):- Three-piece comments that have a start string, an end string, and optional  lines in between.  The strings for the start, middle and end are different.  An example is the C style comment:        /*         * this is a C comment         */The start would be #, with nesting allowed:  n     Nested comment.  Nesting with mixed parts is allowed.  If 'comments'        is n:),n:> a line starting with > ) > is a comment.But not requiring a blank space after (so ## would work), so omitting b:  b     Blank (<Space>, <Tab> or <EOL>) required after {string}.The middle would be #, without nesting, but inserting a space:  {digits}        When together with 's' or 'e': add {digit} amount of offset to an        automatically inserted middle or end comment leader. The offset begins        from a left alignment. See below for more details.So:set comments+=sn:#,mb1:#And now ##<CR> gives:### _Similarly, for your Stata file, you can set comments like so:set comments+=ns:*,mb1:*Check what it is first, and modify it appropriately.