簡體   English   中英

如何保存到Vim中時自動格式化git mailmap文件?

[英]How can I auto-format a git mailmap file on save in Vim?

我將mailmap文件用於一些git倉庫。 文件中的行可以采用以下格式之一

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>

但我不確定如何實現實際命令。

如果您使用的是Linux,則可以使用column 但是我們需要標記每列的第一行。 為此,我在每個部分之前使用sed在此處添加#:

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

您應該能夠輕松地擴展它和/或在BufWritePre vim中直接使用s命令。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM