Skip to content

Commit 19d681f

Browse files
committed
Improve indent for comment
1 parent e443cdc commit 19d681f

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

indent/python.vim

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,17 @@ function! GetPEP8PythonIndent() abort
4444
endif
4545

4646
" keep current indent
47-
let colon = getline(v:lnum)[col('.') - 2] ==# ':'
47+
let l = getline(v:lnum)
48+
let colon = l[col('.') - 2] ==# ':'
4849
if s:synmatch(v:lnum, 1, s:syn_str) != -1 && s:synmatch(v:lnum - 1, 1, s:syn_str) != -1
4950
" inside string
5051
return -1
5152
elseif colon && col('.') < col('$')
5253
" : is not at EOL
5354
return -1
55+
elseif l =~# '^\s*#'
56+
" comment
57+
return -1
5458
endif
5559

5660
" indent for bracket

test/indent.vimspec

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,21 @@ Describe filetype indent
9595
End
9696
End
9797

98+
Describe comment
99+
It keeps the current indent
100+
let in = "def spam():\<CR>if True:\<CR>pass\<CR>"
101+
let in .= "0\<C-D>def eggs():\<CR>\pass\<Esc>\<C-V>0kI# \<Esc>gg=G"
102+
let out = [
103+
\ 'def spam():',
104+
\ ' if True:',
105+
\ ' pass',
106+
\ '# def eggs():',
107+
\ '# pass',
108+
\]
109+
Assert Equals(Insert(in), Buffer(out))
110+
End
111+
End
112+
98113
Describe line continuation
99114
It increases the indent level
100115
let in = "i = 1 + \\\<CR>2 + \\\<CR>3"

0 commit comments

Comments
 (0)