Vim:重新格式化和重新评论的自动化方式?
发布时间:2020-12-15 21:08:26 所属栏目:安全 来源:网络整理
导读:我在代码中有一些文档,我想要很好地格式化: # 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 我安装了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 我安装了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 我想要一些自动生成这样的代码的方法.也就是说,包裹到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 我正在寻找的是: # 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 是否可以在现有的插件或热键序列中执行此操作?我知道gq,它会将文本重新格式化为在vim中设置的字符宽度,但它不会在注释等内容中添加缩进. 解决方法
您可以使用formatlistpat选项(:set fo = n需要工作):
删除# :%s/^# // 2.设置flp选项 :setl flp=^[^-]*-s 3.做格式化 gggqG 4.前置# :%s/^/# / 您还可以使用indentexpr选项: 2A.设置inde选项 :setl inde=15 2B.插入空行 :g/^/pu_ 5.删除空注释 :g/^# $/d (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |