I have a file with the following content:
/** doxygen comment for enum member1 */
COMMON_PREFIX_name1 = 1,
/** doxygen comment for enum member2 */
COMMON_PREFIX_name2 = 2,
/** doxygen comment for enum member3 */
COMMON_PREFIX_name3 = 3,
/** doxygen comment for enum member4 */
COMMON_PREFIX_name4 = 4,
...
Is is possible to sort the definitions by the name1, name2, etc. suffixes in the member names, and keep each comment above the corresponding definition?
Sorting text in Vim is easy! Select the text, then press : , type sort , then hit enter! It'll sort the whole document by default, but you can enter a range too.
I propose the following sequence of actions.
Join the paired lines:
:g/^\s*COMMON_PREFIX_/-j!
Sort the joined lines by the variable names’ suffixes:
:sort#\*/\s*COMMON_PREFIX_#
Split the sorted lines back:
:g#\*/\zs\ze\s*COMMON_PREFIX_#s//\r/
You can run all three commands at once:
:exe'g/^\s*COMMON_PREFIX_/-j!' | sort#\*/\s*COMMON_PREFIX_# | g#\*/\zs\ze\s*COMMON_PREFIX_#s//\r/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With