6

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

4 Answers 4

8

Note.

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.


Order of mess:

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*/

Fix:

filetype indent plugin on

" Or
filetype plugin indent on

" Or with correct order:
filetype plugin on
filetype indent on

PS.

In any case plugin should be processed before indent.

To check order of inclusion/processing have a look at :scriptnames.

Sign up to request clarification or add additional context in comments.

1 Comment

Although Lekensteyn offers a workaround that should patch the issue, this response seems to identify the underlying cause. When I make a single line in vimrc with filetype plugin indent on, then my comments value is correct when I load a PHP buffer without having to hijack the comments value manually.
3

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!

1 Comment

As you say "With the default settings" it might not be the case, but sure it is not due to wrong order of indent and plugin? Ref. my own answer.
1

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!

Comments

0

The php.vim file should be in your ftplugin folder in $VIMRUNTIME.

In version 7.2 of vim, the comments line is line 74 in that file.

Did that file get deleted or moved?

2 Comments

No, it's still there. Maintainer: Dan Sharp URL: dwsharp.users.sourceforge.net/vim/ftplugin
do you have any files in your personal .vim/ftplugin that could be overriding the comments? Or your .vim/filetype.vim for that matter?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.