The attached patch sets the 'textwidth' and 'comments' options, and modifies the 'formatoptions' option, to improve formatting of comments in vim, especially documentation blocks. I explain these settings in the comments in the vimrc file and in this comment. The 80-character limit for comments is recommended here.

Comments

benjifisher’s picture

Status: Active » Needs review

I forgot to mark it "needs review."

benjifisher’s picture

StatusFileSize
new1.12 KB

I re-rolled the patch. It now applies to ftplugin/php_drupal.vim.

Niklas Fiekas’s picture

Status: Needs review » Reviewed & tested by the community

Awesome! I had something that had the same behaviour in an old copy-paste created .vimrc - then I lost it and I've always wanted it back ;)

One thing that could be better, though it never happens in real life: // aneightycharacterlongwordthathasnospaces - shouldn't be split on to multiple lines.

One other thing is, that /** is easily closed by */<enter>, while // foo<enter> starts a new // which is useful on the one hand, but annoying if you don't need it. Could // foo<enter><backspace> delete the whole new // or how is it supossed to be used?

benjifisher’s picture

Niklas:

Thanks for testing. If we only allowed people who are experts on vim script to review our changes, it would slow us down a lot. If there are no further comments in the next few days, I will add something to the documentation and commit a patch.

I am not sure about your first comment. I tried

  // a234567890b234567890c234567890d234567890e234567890e234567890f234567890g234567890h234567890

and the line did not break. Is that good or bad?

Closing comments is even easier than you say. After starting a comment with /** the * will be entered automatically on a new line; you only have to type the / to close the comment. I mention this in the comments of ftplugin/php_drupal.vim.

A Google search for "vim remove comment leader" turns up a suggestion I made almost exactly 10 years ago on the vim users' mailing list: use <C-U> to delete the inserted comment leader. You could make a key mapping and function, but it might be easier to re-train your fingers. After all, your little finger is never far from the control key, right? http://tech.groups.yahoo.com/group/vim/message/21587

Another possibility for the comments option is the C default,
set comments=s1:/*,mb:*,ex:*/,://
As far as I can tell, this behaves identically for doc blocks, but it also recognizes comments that start with /* instead of /**. I am inclined to leave the setting as we have it now, to discourage commenting that does not follow Drupal coding standards. I feel kind of like Big Brother, though.

Niklas Fiekas’s picture

There is no wrong line break and thats awesome - the line break i saw came from a too small terminal :D

<C-U> works very well, too. I keep getting faster there.

Only allowing /** to start docblocks is ok, I think. It's not even Drupal only.

If there are no other technical issues I think it's ready to be comitted. It's a really useful feaure - thank you for creating the patch and explaining everything.

benjifisher’s picture

Status: Reviewed & tested by the community » Fixed
StatusFileSize
new2.06 KB

I have committed the attached patch. It is the same as in #2 plus a few lines added to doc/drupal.txt.

Niklas Fiekas’s picture

benjifisher++ ;)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.