Vim的不同文本宽度为多行C注释? [英] Vim different textwidth for multiline C comments?
问题描述
在我们的C ++ code碱基我们保持99列线,但79几家,奇数列多行注释。是否有一个很好的策略,自动将做到这一点?我假设模式是已知的,因为智能注释行,加入和领先*插入。
In our C++ code base we keep 99 column lines but 79-some-odd column multiline comments. Is there a good strategy to do this automagically? I assume the modes are already known because of smart comment line-joining and leading * insertion.
推荐答案
显然这两个code和评论使用相同的文本宽度
选项。至于我可以看到,唯一的诀窍就是动态地设置此选项:
Apparently both code and comments use the same textwidth
option. As far as I can see, the only trick is to set this option dynamically:
:autocmd CursorMoved,CursorMovedI * :if match(getline(.), '^\s*\*') == 0 | :setlocal textwidth=79 | :else | :setlocal textwidth=99 | :endif
下面,当我们在评论中关键部分的检测。如果你只格式化的意见是这样的:
Here the critical part is detecting when we are in a comment. If you only format comments this way:
/*
* my comment
*/
我正则表达式应该工作...除非你在code开头的行 *
(我的猜测可以在发生Ç
,不经常在 C ++
)。如果您使用的意见是这样的:
my regex should work... unless you have lines in the code starting with *
(which I guess can happen in C
, less frequently in C++
). If you use comments like this:
// comment line 1
// comment line 2
正则表达式更简单写。如果要涵盖所有可能的情况,包括拐角情况,嗯...我想,最好的办法是定义一个单独的检测功能,并调用从:自动命令
而不是匹配()
。
这篇关于Vim的不同文本宽度为多行C注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!