【问题标题】:How can I auto-format a git mailmap file on save in Vim?如何在 Vim 中保存时自动格式化 git mailmap 文件?
【发布时间】:2019-03-10 10:33:41
【问题描述】:

我将邮件映射文件用于一些 git 存储库。文件中的行可以是formats 之一:

Proper Name <commit@email.xx>
<proper@email.xx> <commit@email.xx>
Proper Name <proper@email.xx> <commit@email.xx>
Proper Name <proper@email.xx> Commit Name <commit@email.xx>

我想将行格式化为表格,列用 2 个空格分隔,例如

Some Dude     <some@dude.xx>              <bugs@company.xx>
Other Author  <other@author.xx>           <bugs@company.xx>
Other Author  <other@author.xx>           <nick2@company.xx>
Santa Claus   <santa.claus@northpole.xx>  <me@company.xx>

如何让 Vim 在保存时以这种方式重新格式化邮件映射文件(例如,如果新名称对于列大小来说太大)?我想可以使用这样的自动命令:

autocmd BufWritePre mailmap :<reformat_cmd>

但我不确定如何实现实际的命令。

【问题讨论】:

  • 你可以使用像this one这样的对齐插件

标签: linux git vim autocommand mailmap


【解决方案1】:

如果您使用的是 Linux,则可以使用 column。但是我们需要标记每列首先结束的位置。为此,我使用sed在每个部分之前添加#:

:autocmd BufWritePost mail silent :%!sed 's/^\([^<]\+\)\?*\(<[^>]\+>\)*\([^<]\+\)\?*\(<[^>]\+>\)\?/\1 \#\2 \#\3
 \#\4/' | column -t -s '\#'

您应该能够轻松扩展它和/或直接在 vim 中的 BufWritePre 上使用 s 命令。

【讨论】:

    猜你喜欢
    • 2014-11-30
    • 2018-08-05
    • 2012-06-13
    • 2010-12-13
    • 1970-01-01
    • 2017-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多