Let's say I have a bunch of vim mappings (although it could be code in any language), each of which with a comment line or lines above them:
(using #
not "
so the comments get highlighted nicely)
# A comment
nnoremap <Leader>a ...
# D comment
nnoremap <Leader>d ...
# B comment
nnoremap <Leader>b ...
# H comment
nnoremap <Leader>h ...
# C comment
# comment cont'd
# comment cont'd
nnoremap <Leader>c ...
# F comment
nnoremap <Leader>f ...
# G comment
nnoremap <Leader>g ...
# E comment
nnoremap <Leader>e ...
How do I sort these lines, while preserving the association of comments with the first non-comment line below them?
i.e. I want this output:
# A comment
nnoremap <Leader>a ...
# B comment
nnoremap <Leader>b ...
# C comment
# comment cont'd
# comment cont'd
nnoremap <Leader>c ...
# D comment
nnoremap <Leader>d ...
# E comment
nnoremap <Leader>e ...
# F comment
nnoremap <Leader>f ...
# G comment
nnoremap <Leader>g ...
# H comment
nnoremap <Leader>h ...