VIM:按功能名称排序 [英] VIM: Sort by Function name

查看:131
本文介绍了VIM:按功能名称排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的menu.vim文件中有很多功能。

是否可以选择它们(通过我)并按函数名称对它们进行排序?

p.e。

从乐趣中找到线条!或函数!
到行endfun



找到函数的名称并根据函数的名称对整个块进行排序(从az)



有时我在函数名称上方有一行注释。

是否可以使用它?

解决方案

这可能有点棘手,但这是一个尝试性的方法:


  • 选择不在源文件中的替换模式,例如@@@

  • g / fun \%[ction]!\ = / /然后,选择所有单行,并使用'<,'> sort / fun \%[ction]!\ = /

  • %s / @ @@ / \r / g


I have a lot of functions in my menu.vim file.
Would it be possible to select them (by me) and sort them by function name?

p.e.
find lines from fun! or function!
to line endfun

find name of function and sort the whole block based on the name of function (from a-z)

Sometimes I have one line of comment above the function name.
Can it be taken with it?

解决方案

This could be a bit tricky but here is a tentative way to do it:

  • choose a substitution pattern that is not in your source file, like @@@
  • g/fun\%[ction]!\= /,/endf\%[unction]/ s/$\n/@@@
  • Then, select all one-liners and use '<,'>sort /fun\%[ction]!\=/
  • %s/@@@/\r/g

这篇关于VIM:按功能名称排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆