Sorting .gitmodules entries with Vim

Applying a similar trick to the one in "Sorting functions by name in Vim", we can sort the entries inside a .gitmodules file as follows:

" (1) Collapse each section onto one line.
" Specifically, replace every newline + tab with @@@

(2) Do the sorting

(3) Replace every @@@ by a newline + tab:

Note the gotcha here: \n matches newlines in the search pattern, but to insert a newline in the replacement string we use \r.