@@ -440,13 +440,15 @@ let &cpo = s:cpo_save
440440unlet s: cpo_save
441441
442442function ! Fixedgq (lnum, count )
443+ let l: tw = &tw ? &tw : 72 ;
444+
443445 let l: count = a: count
444446
445447 if mode () == ' i' " gq was not pressed, but tw was set
446448 return 1
447449 endif
448450
449- if len (getline (a: lnum )) < 80 && l: count == 1 " No need for gq
451+ if len (getline (a: lnum )) < l: tw && l: count == 1 " No need for gq
450452 return 1
451453 endif
452454
@@ -460,9 +462,9 @@ function! Fixedgq(lnum, count)
460462
461463 let l: winview = winsaveview ()
462464
463- call cursor (a: lnum , 81 )
465+ call cursor (a: lnum , l: tw + 1 )
464466 let orig_breakpoint = searchpairpos (' ' , ' ' , ' \.' , ' bcW' , ' ' , a: lnum )
465- call cursor (a: lnum , 81 )
467+ call cursor (a: lnum , l: tw + 1 )
466468 let breakpoint = searchpairpos (' ' , ' ' , ' \.' , ' bcW' , s: skip_expr , a: lnum )
467469
468470 " No need for special treatment, normal gq handles edgecases better
@@ -473,7 +475,7 @@ function! Fixedgq(lnum, count)
473475
474476 " Try breaking after string
475477 if breakpoint[1 ] <= indent (a: lnum )
476- call cursor (a: lnum , 81 )
478+ call cursor (a: lnum , l: tw + 1 )
477479 let breakpoint = searchpairpos (' \.' , ' ' , ' ' , ' cW' , s: skip_expr , a: lnum )
478480 endif
479481
0 commit comments