My vim used to auto-continue comments in php. For example:
/* | <- cursor here
Then, pressing Enter gives me:
/*
* | <- cursor here
and again, gives me:
/*
*
* | <- cursor here
etc...
As far as I understand it, this is controlled by the comments
and formatoptions
options. However, whenever I open a php file now, comments
is set to:
s:<!--,m: ,e:-->
I've looked all over my ~/.vim folder, as well as the $VIMRUNTIME folder, and I can't find out where/why this changed, and why the comments
option is being set incorrectly.
Here's a link to my .vimrc
http://pastebin.com/f1509ce65
Note that this issue can also arise if one have filetype indent on
and plugin on
at separate lines in .vimrc:
filetype indent on
filetype plugin on
This causes $VIMRUNTIME/indent/php.vim
to be processed before $VIMRUNTIME/ftplugin/php.vim
.
The indent/php.vim
file resets 'comments'
, but ftplugin/php.vim
does not.
indent/php.vim
get sourced and comments
correctly set:
setlocal comments=s1:/*,mb:*,ex:*/,://,:#
Then ftplugin/php.vim
get sourced. It again sources ftplugin/html.vim
by:
runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
which result in ftplugin/html.vim
being processed and setting:
setlocal commentstring=<!--%s-->
setlocal comments=s:<!--,m:\ \ \ \ ,e:-->
Later on in ftplugin/php.vim
the commentstring
is reset but not comments
:
setlocal commentstring=/*%s*/
filetype indent plugin on
" Or
filetype plugin indent on
" Or with correct order:
filetype plugin on
filetype indent on
In any case plugin should be processed before indent.
To check order of inclusion/processing have a look at :scriptnames
.
With the default settiings of version 7.3 (patchset 754), I observe the same bug as in your original post:
/**<ENTER>
Expected result:
/**
* <cursor>
Actual result:
/**
<cursor>
The solution consists of two steps:
The modification to my vimrc that takes these two steps into account:
au FileType php setlocal comments=s1:/*,mb:*,ex:*/,://,:#
au FileType php setlocal formatoptions+=cro
Hurrah!
Found it. I had a funky .vim/indent/php.vim file that somehow was screwing it up.
Deleted it, and the functionality I was looking for returned. Thanks tho!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With