如何让vim自动换行三个斜杠的注释?

19

我经常使用gq将较长的注释限制在一定数量的字符内,如果我使用///* /*来注释我的代码,则这个功能可以很好地发挥作用:

// here is a simple comment that exceeds my line width 
// across multiple lines

// here is a simple comment that
// exceeds my line width across
// multiple lines

然而,如果我有三斜杠注释,例如用于doxygen,它无法工作:

/// here is a simple comment that exceeds my line width
/// across multiple lines

/// here is a simple comment that
// exceeds my line width / across
// multiple lines

vim似乎将最后一个斜杠包含在文本中,而不承认它是注释的一部分。我该如何解决这个问题呢?以下是我希望在选中三条斜线注释并按下gq时看到的结果:

/// here is a simple comment that
/// exceeds my line width across
/// multiple lines
注意,我不想影响普通的注释的现有行为。
我正在使用vim 7.4.52。
1个回答

27
将以下内容添加到你的.vimrc文件中即可:
autocmd Filetype c,cpp set comments^=:///

有关评论格式的帮助可在:h format-comments找到。


两年后,这个答案仍然非常相关和有用。 :) - merlin2011

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接