我在代码中有一些文档,我想要很好地格式化:
# book_id - integer
# chapter_id - integer (Optional)
# relative_url - Text: the url of the screencast file on S3, relative to the book's url
# view_count - integer
Run Code Online (Sandbox Code Playgroud)
我安装了Tabular.vim,这让我走得很远:
# book_id - integer
# chapter_id - integer (Optional)
# relative_url - Text: the url of the screencast file on S3, relative to the book's url
# view_count - integer
Run Code Online (Sandbox Code Playgroud)
我想要一些自动生成这样的代码的方法.也就是说,包裹到79个字符,如果从前一个注释继续一行,则缩进.我得到的是这个:
# book_id - integer
# chapter_id - integer (Optional)
# relative_url - Text: the url of the screencast file on S3, relative to the
# book's url
# view_count - integer
Run Code Online (Sandbox Code Playgroud)
我正在寻找的是:
# book_id - integer
# chapter_id - integer (Optional)
# relative_url - Text: the url of the screencast file on S3, relative to the
# book's url
# view_count - integer
Run Code Online (Sandbox Code Playgroud)
是否可以在现有的插件或热键序列中执行此操作?我知道gq,它会将文本重新格式化为在vim中设置的字符宽度,但它不会在注释等内容中添加缩进.
您可以使用该formatlistpat选项(:set fo+=n需要工作):
#:%s/^# //
Run Code Online (Sandbox Code Playgroud)
flp选项:setl flp=^[^-]*-\\s
Run Code Online (Sandbox Code Playgroud)
gggqG
#:%s/^/# /
Run Code Online (Sandbox Code Playgroud)
您还可以使用以下indentexpr选项:
inde选项:setl inde=15
Run Code Online (Sandbox Code Playgroud)
:g/^/pu_
Run Code Online (Sandbox Code Playgroud)
:g/^# $/d
Run Code Online (Sandbox Code Playgroud)