File tree 1 file changed +19
-12
lines changed
1 file changed +19
-12
lines changed Original file line number Diff line number Diff line change @@ -90,21 +90,28 @@ endfunction
90
90
function ! s: sortInsideGroups ()
91
91
call cursor (1 , 1 )
92
92
93
- while (1 )
93
+ let start = 1
94
+ let end = 1
95
+
96
+ " repeat until we find no more matches
97
+ while (start > 0 && end > 0 )
94
98
let pos = line (" ." )
95
- let start = search (' ^import' ) " find first line with import
96
- let end = search (' ^\import.*\n\(import\)\@!' ) " find first non-import line
97
-
98
- " if the next match is above the current cursor position the search has
99
- " wrapped and we're done
100
- " also covered is the case when the import is the last line in the file
101
- " with no blank line after it
102
- if start < pos || end < start
103
- break
104
- end
99
+ " find first line with import
100
+ let start = search (' ^import' , ' cW' )
101
+ " find next line which starts with an import, ends with a newline
102
+ " and the next line is not an import
103
+ " the 'c' flag accepts matches at the current position allowing single line groups
104
+ let end = search (' ^\import.*\n\(import\)\@!' , ' cW' )
105
105
106
106
execute start ' ,' end ' sort i'
107
- call cursor (end ,0 )
107
+
108
+ call cursor (end + 1 , 0 )
109
+
110
+ " stop if end is the last line in the file
111
+ if line (" $" ) == end
112
+ break
113
+ endif
114
+
108
115
endwhile
109
116
endfunction
110
117
You can’t perform that action at this time.
0 commit comments