0

I use mailmap files for some git repos. The lines in the files can be in one of these 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>

I want to keep the lines formatted as a table with columns separated with 2 spaces, e.g.

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>

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.

planetp
  • 14,248
  • 20
  • 86
  • 160

1 Answers1

0

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 using sed:

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

You should be able to easily extend it and/or use s command directly in vim on BufWritePre.

Karol Samborski
  • 2,757
  • 1
  • 11
  • 18