1- let s: eol_pattern = ' \s*\%(\/\/.*\)\=$'
2-
31function ! sj#go#SplitImports ()
4- if getline (' .' ) = ~ ' ^import ".*"$'
5- call sj#Keeppatterns (' s/^import \(".*"\)$/import (\r\1\r)/' )
2+ let pattern = ' ^import\s\+\(\%(\k\+\s\+\)\=\%(".*"\)\)$'
3+
4+ if getline (' .' ) = ~ pattern
5+ call sj#Keeppatterns (' s/' . pattern . ' /import (\r\1\r)/' )
66 normal ! k ==
77 return 1
88 else
@@ -11,10 +11,10 @@ function! sj#go#SplitImports()
1111endfunction
1212
1313function ! sj#go#JoinImports ()
14- if getline (' .' ) = ~ ' ^import ($' &&
15- \ getline (line (' .' ) + 1 ) = ~ ' ^\s*".*"$' &&
14+ if getline (' .' ) = ~ ' ^import\s* ($' &&
15+ \ getline (line (' .' ) + 1 ) = ~ ' ^\s*\%(\k\+\s\+\)\= ".*"$' &&
1616 \ getline (line (' .' ) + 2 ) = ~ ' ^)$'
17- call sj#Keeppatterns (' s/^import (\_s\+\(".*"\)\_s\+)$/import \1/' )
17+ call sj#Keeppatterns (' s/^import (\_s\+\(\%(\k\+\s\+\)\=\( ".*"\) \)\_s\+)$/import \1/' )
1818 return 1
1919 else
2020 return 0
@@ -92,7 +92,7 @@ endfunction
9292
9393function ! sj#go#JoinVars () abort
9494 let pattern = ' ^\s*\(var\|type\|const\)\s\+('
95- if sj#SearchUnderCursor (pattern. s: eol_pattern ) <= 0
95+ if sj#SearchUnderCursor (pattern) <= 0
9696 return 0
9797 endif
9898
@@ -325,7 +325,7 @@ function! sj#go#JoinFuncCallOrDefinition()
325325 return 0
326326 endif
327327
328- if strpart (getline (' .' ), 0 , col (' .' )) = ~ ' \(var\|type\|const\)\s\+($'
328+ if strpart (getline (' .' ), 0 , col (' .' )) = ~ ' \(var\|type\|const\|import\ )\s\+($'
329329 " This isn't a function call, it's a multilne var/const/type declaration
330330 return 0
331331 endif
0 commit comments