It is not an error, or as the saying goes, "T'aint a bug, it's a
feature". IIUC many standard ftplugins have long set formatoptions+=ro �
of course, when you create a [NoName] file it still has no filetype
(even if you give the file a name without reloading it) and therefore no
ftplugin has set anything special for it. As soon as you name it _and_
reload it, the ftplugins apply.
See
:help 'formatoptions'
:help fo-table
- Flag r means: Automatically insert the current comment leader after
hitting <Enter> in Insert mode.
- Flag o means: Automatically insert the current comment leader after
hitting 'o' or 'O' in Normal mode.
To avoid these in C and C++ files, add the following two-line file as
$HOME/.vim/after/ftplugin/c.vim (for Unix, Linux or Mac OS X) or
$HOME/vimfiles/after/ftplugin/c.vim (in Vim notation, for Windows):
" disable comment leader insertion
setlocal fo-=r fo-=o
(the C++ ftplugin does nothing other than invoke the C ftplugin). If the
directories don't yet exist, create them too.
The above is "per-filetype" (with the exception that the C ftplugin is
also used for C++), so if you want the same for, let's say, javascript
and CSS (which have similar comment structures as C and C++), you'll
have to drop copies of the same file as javascript.vim and css.vim in
the same directory: you get the drift. For a blanket disable, you may
use instead
autocmd FileType * setlocal fo-=r fo-=o
which must be placed _after_ "filetype plugin on" in your .vimrc or
_vimrc in order to have an effect; *but* if at any time you use
":filetype plugin off" followed by ":filetype plugin on" this
autocommand will lose its effect, which is not the case of the scripts
in .../after/ftplugin/.
See also the following recent threads on vim_use:
- Permanent disable comment next line
(about 'formatoptions' flags r and o)
- Please fix: make Windows Vim use same files as unix. No reason not to
and it's confusing in mixed envirionments.
(started as: Can't get vim to use custom color in personal folder(finds
.vimrc/.gvimrc but not .vim/colors/name.vim) )
(about ~/vimfiles/ vs. ~/.vim/)
Best regards,
Tony.
--
Blessed are the meek for they shall inhibit the earth.