Skip to content

Commit 6a7f996

Browse files
committed
Fix bug when using gq on multiple lines and fix vimlint errors
1 parent a2500d6 commit 6a7f996

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

indent/python.vim

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ setlocal expandtab
1515
setlocal nolisp
1616
setlocal autoindent
1717
setlocal indentexpr=GetPythonPEPIndent(v:lnum)
18-
setlocal formatexpr=Fixedgq(v:lnum,v:count,v:char)
18+
setlocal formatexpr=Fixedgq(v:lnum,v:count)
1919
setlocal indentkeys=!^F,o,O,<:>,0),0],0},=elif,=except
2020
setlocal tabstop=4
2121
setlocal softtabstop=4
@@ -257,11 +257,20 @@ function! GetPythonPEPIndent(lnum)
257257
endfunction
258258

259259

260-
function! Fixedgq(lnum, count, char)
261-
let count = a:count
262-
if len(getline(a:lnum)) < 80 " No need for gq
260+
function! Fixedgq(lnum, count)
261+
let l:count = a:count
262+
if len(getline(a:lnum)) < 80 && l:count == 1 " No need for gq
263263
return 1
264264
endif
265+
266+
" Put all the lines on one line and do normal spliting after that
267+
if l:count > 1
268+
while l:count > 1
269+
let l:count -= 1
270+
normal J
271+
endwhile
272+
endif
273+
265274
let l:winview = winsaveview()
266275

267276
" Check if the line is part of a docstring
@@ -303,17 +312,12 @@ function! Fixedgq(lnum, count, char)
303312
if breakpoint[1] != 0
304313
call feedkeys("r\<CR>")
305314
else
306-
let count = count - 1
307-
normal j
315+
let l:count = l:count - 1
308316
endif
309317

310318
" run gq on new lines
311-
if count > 1
312-
call feedkeys("gq".a:count."j")
313-
elseif count == 1
319+
if l:count == 1
314320
call feedkeys("gqq")
315-
else
316-
normal k
317321
endif
318322

319323
return 0

0 commit comments

Comments
 (0)