开发者

Is there a way to fix vim not-noticing python if statements that have comments?

开发者 https://www.devze.com 2023-01-08 17:18 出处:网络
Consider the following block of code- if (1==1):#Go forever print \"Wooo.\" Vim doesn\'t see the :, due to the comment, so it insists that the print should be at the same indent level as the \"if\"

Consider the following block of code-

if (1==1):#Go forever
    print "Wooo."

Vim doesn't see the :, due to the comment, so it insists that the print should be at the same indent level as the "if"

using http://开发者_如何学JAVAwww.vim.org/scripts/script.php?script_id=974

Any thoughts would be appreciated.


Find this in the .vim file:

" If the previous line ended with a colon, indent relative to
" statement start.
if pline =~ ':\s*$'

change it to...

" If the previous line ended with a colon, indent relative to
" statement start.
if pline =~ ':\s*\(#.*\)\?$'

That will make it also match lines that end with a colon followed by a comment.

0

精彩评论

暂无评论...
验证码 换一张
取 消