是否可以在vim中对一组行进行排序? [英] Is it possible to sort a groups of lines in vim?
问题描述
据我所知,vim的:sort方法将对每一行进行排序.我有一些代码,每组3行.我该如何分类?请忽略糟糕的代码,这是一个遗留应用程序:'(
As far as I know vim's :sort method will sort each line. I have some code that is in groups of 3 lines. How can I sort this? Please ignore the shitty code, it's a legacy app :'(
我想按大小写"AF"行进行排序,但忽略(分组)国家/地区和分界线
I would like to sort by the case 'AF' line but ignore (group) the country and break line
case 'AF':
country = 'Afghanistan';
break;,
case 'AL':
country = 'Albania';
break;,
case 'DZ':
country = 'Algeria';
break;,
case 'AS':
country = 'American Samoa';
break;,
case 'AD':
country = 'Andorra';
break;,
case 'AO':
country = 'Angola';
break;,
case 'AI':
country = 'Anguilla';
break;,
case 'AQ':
country = 'Antarctica';
break;,
case 'AG':
country = 'Antigua And Barbuda';
break;,
case 'AR':
country = 'Argentina';
break;,
case 'AM':
country = 'Armenia';
break;,
case 'AW':
country = 'Aruba';
break;,
case 'AU':
country = 'Australia';
break;,
case 'AT':
country = 'Austria';
break;,
case 'AZ':
country = 'Azerbaijan';
break;,
case 'BS':
country = 'Bahamas';
break;,
case 'BH':
country = 'Bahrain';
break;,
case 'BD':
country = 'Bangladesh';
break;,
case 'BB':
country = 'Barbados';
break;,
case 'BY':
country = 'Belarus';
break;
推荐答案
我的 AdvancedSorters插件通过简单的自定义命令实现@Halst和@SatoKatsura建议的算法(加入,排序然后取消加入):
My AdvancedSorters plugin implements the algorithm suggested by @Halst and @SatoKatsura (joining, sorting, then unjoining) as a simple custom command:
:SortRangesByHeader /^case/
该插件实现了其他各种排序方法,例如按倍数,范围等.
The plugin implements various other sorting methods, e.g. by folds, ranges, etc.
这篇关于是否可以在vim中对一组行进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!