I use mailmap files for some git repos. The lines in the files can be in one of these formats:
Proper Name <[email protected]>
<[email protected]> <[email protected]>
Proper Name <[email protected]> <[email protected]>
Proper Name <[email protected]> Commit Name <[email protected]>
I want to keep the lines formatted as a table with columns separated with 2 spaces, e.g.
Some Dude <[email protected]> <[email protected]>
Other Author <[email protected]> <[email protected]>
Other Author <[email protected]> <[email protected]>
Santa Claus <[email protected]> <[email protected]>
How can I make Vim reformat a mailmap file this way on save (e.g. if a new name is too large for the column size)? I guess it's possible with an autocommand like this:
autocmd BufWritePre mailmap :<reformat_cmd>
but I'm not sure how to implement the actual command.
If you're on Linux you can use
column. But we need to mark where each column ends first. To do it I add here # before each section usingsed:You should be able to easily extend it and/or use
scommand directly in vim onBufWritePre.