VIM: Sort by function name

I have many functions in the menu.vim file.
Is it possible to select them (by me) and sort them by function name?

pe
find the lines of pleasure! or features!
to line endfun

find function name and sort the whole block based on function name (from az)

Sometimes I have one line of comment above the function name.
Can I take with me?

+5
source share
1 answer

It may be a bit complicated, but here is a preliminary way to do it:

  • select a lookup template that is not in the source file, for example @@@
  • g/fun\%[ction]!\= /,/endf\%[unction]/ s/$\n/@@@
  • Then select all single line and use '<,'>sort /fun\%[ction]!\=/
  • %s/@@@/\r/g
+7

All Articles