问题
When setting the formatoptions
to include the o
flag, pressing o
or O
on a commented line will "inherit" the leading comment marker.
However, for Stata
, only \\
had been recognized as a "valid comment". The other two types of commenting had been ignored, by the set formatoptions+=o
.
May I name multiple leading characters/strings to be the "comment marker" in Vim? Here goes how "comment lines" had been defined in the syntax file for Stata
.
(From C:/vim/vimfiles/syntax/stata.vim
)
" comments - single line
" note that the triple slash continuing line comment comes free
syn region stataStarComment start=/^\s*\*/ end=/$/ contains=stataComment oneline
syn region stataSlashComment start="\s//" end=/$/ contains=stataComment oneline
syn region stataSlashComment start="^//" end=/$/ contains=stataComment oneline
" comments - multiple line
syn region stataComment start="/\*" end="\*/" contains=stataComment
I don't see anything special about the //
as a marker, at least in the syntax file.
Thank you in advance.
回答1:
The settings you are looking for is the comments
settings.
Since stata file don't appear to have a filetype plugin, nobody sets this and it stays at the default (which isn't very good).
Since stata comments are similar to c, we can look at how c handles the comments. In $VIMRUNTIME/ftplugin/c.vim
we find
setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://
If you add that to ~/.vim/ftplugin/stata.vim
you should have c style comments added to stata files. (This seems to handle all three types even though the leading *
isn't a valid c comment.)
Relevant help topics :h 'comments'
and :h format-comments
. The second help topic will explain what all the options for comments
.
来源:https://stackoverflow.com/questions/28665317/how-can-i-customize-comment-marker-in-vim