views:

1186

answers:

4

From here: Vim Comment HOWTO

I've been able to type the

:set comments=sl:/*,mb:*,elx:*/

command. Because my sas code requires this style comments:

    /*
    * This is the comment
    */

The problem is once I type this set command I don't know how to actually get those comments to add to the code... the instructions say to type "/*" but in insert mode this just acts normally, and in command mode this does a find on "*".

How do I get this to work? and Are there better ways than this to automatically insert comment marks?

Thanks,

Dan

+1  A: 

Which language?

In C Vim autoloads this setting for comments:

" Set 'comments' to format dashed lists in comments.
setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://

Which works as you'd expect. Maybe you need to add that to the ftplugin for the language/extension you're using?

John Weldon
OP mentions SAS code
webwesen
+1  A: 

I have this abbreviation in my .vimrc:

" /// -> insert javadoc comment
iab <buffer> /// /**^M *^M*/^[0A

where ^[0A is ctrl-v + up.
Type /// in insert mode to get a comment like

/**
 * 
 */
Paolo Tedesco
+1  A: 

this Vim script might solve your problem - just put it into "vimXY/syntax" folder

webwesen
+4  A: 

By default, Vim doesn't automatically insert the newlines or end markers for you. Instead, it makes it easy to insert those as you type, as long as 'formatoptions' contains r:

:set formatoptions+=r

After this, start typing your comment as normal: "/*<Enter>" (in insert mode). After you hit the Enter key, the comment leader (an asterisk and a space) should appear automatically on the next line, ready for you to start typing. When your comment is complete, end it with "<Enter>/"; the <Enter> moves to the next line, and the slash becomes the second character of the end marker. Yes, it will remove the space for you, but only right after you hit enter.

To make editing this type of comment easier, you wish to add the c and/or o characters to formatoptions, as well. The former allows comments to auto-wrap, and the latter inserts the comment leader when you create a new line inside the comment using normal-mode commands.

eswald