4

我的 .gvimrc 文件中有以下行,可以在 80 个字符处自动换行。

set textwidth=80 

我还有以下几行来控制 C++ 代码缩进。

set smartindent
set cindent

这在大多数情况下都很好用,但在输入长字符串时有一个限制。自动缩进添加的空格或制表符成为字符串的一部分。例如,换行当前执行以下操作:

puts("I have put `set textwidth=80` in my `.gvimrc` file to make gvim
        automatically wrap long strings like this one.");

而我希望它执行以下操作:

puts("I have put `set textwidth=80` in my `.gvimrc` file to make gvim "
        "automatically wrap long strings like this one.");

这将确保输出中没有虚假的空格,同时保持一致的代码缩进。

有没有办法配置 gvim 来做到这一点?我在互联网和 StackOverflow 上进行了搜索,但无法弄清楚如何/是否可以这样做。

4

2 回答 2

1

'formatoptions'恐怕还没有内置设置。但是,可以使用 custom 自定义格式化gq和中断文本,尽管我已经看到到目前为止很少使用。'textwidth''formatexpr'

如果您不想尝试这样的实现,一个简单的解决方法是设置'colorcolumn';该视觉帮助将帮助您记住Enter在达到文本宽度之前关闭字符串并按下。

于 2012-11-20T15:57:47.907 回答
-1

Have a look at this.

You can use the formatoption command to somewhat solve your problem

于 2012-11-19T15:22:28.860 回答