在 Vim 中,我可以输入如下一行:
- When in the Course of human events it becomes necessary for one people
to dissolve the political bands which have connected them with another
...
Vim 将包裹文本,使其与破折号的右侧对齐。但是,如果我用星号尝试此操作,则会发生以下情况:* When in the Course of human events it becomes necessary for one people
to dissolve the political bands which have connected them with another
...
有没有办法让自动缩进与前导星号一起工作,就像前导破折号一样?
最佳答案
这是使用 comments
完成的设置(参见 :help 'comments'
和 :help format-comments
)。
您需要添加的设置是fb:*
,表示有一种以 *
开头的评论类型和 *
后面必须跟一个空格,并且只在注释的第一行。 Vim 处理剩下的事情。但是,请注意默认设置包括 *
作为多行 C 注释的中间,因此您需要禁用它。
如果连字符前缀和星号前缀的行是您想要像这样工作的唯一行,请执行以下操作:
set comments=fb:-,fb:*
或者,根据需要调整默认评论设置:
:set comments?
显示当前设置和 :help format-comments
解释了这一切意味着什么。如果您希望这是特定于文件类型的,请在
~/.vim/ftplugin
中创建一个文件。 (或 vimfiles
在 Windows 上),文件名为 extension.vim
(例如 txt.vim
用于 .txt
文件)。在这个文件中放置:setlocal comments=fb:-,fb:*
这将配置
comments
设置相关文件类型而不影响其他文件。
关于vim - 如何让 Vim 用缩进包裹带项目符号的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4782462/