怎么能让vim用缩进来包装项目符号文本?

dan*_*dan 9 vim

在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
  ...
Run Code Online (Sandbox Code Playgroud)

和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 ...
Run Code Online (Sandbox Code Playgroud)

有没有办法让自动加注器与领先的星号一起使用,就像它对领先的短划线一样?

DrA*_*rAl 11

这是使用comments设置完成的(请参阅:help 'comments':help format-comments).

您需要添加的设置fb:*,它说,存在与注释的开始类型**必须遵循的一个空白,只是在注释的第一行.Vim处理剩下的事情.但请注意,默认设置包含*在多行C注释的中间,因此您需要禁用此功能.

如果连字符前缀和带星号前缀的行是您想要像这样工作的唯一行,请执行以下操作:

set comments=fb:-,fb:*
Run Code Online (Sandbox Code Playgroud)

或者,根据需要调整默认注释设置::set comments?显示当前设置并:help format-comments解释它的含义.

如果您希望它特定于文件类型,请在~/.vim/ftplugin(或vimfiles在Windows上)使用文件名创建文件extension.vim(例如,txt.vim对于.txt文件).在这个文件中:

setlocal comments=fb:-,fb:*
Run Code Online (Sandbox Code Playgroud)

这将配置comments相关文件类型的设置,而不会影响其他文件.