开发者

Incorrect comments set for php in vim

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 a开发者_运维百科ll 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.

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.


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:

  • Add a command that makes vim detect comments (see Issue 75 for vim on Google Code)
  • Add a command that makes vim automatically insert comment continuations (apply the reverse of Vim: can I disable continuation of comments to the next line?)

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!


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜