当我在Vim中编辑haskell文件时,我的编辑器会自动将超过80个字符的注释包装到下一行.我希望Vim对python文件(和文本文件)使用相同的行为,但我找不到在我的~/.vim/syntax文件夹或任何地方执行此操作的设置vimrc.
以下是我的.vimrc的相关行:
set wrap
set textwidth=80
Run Code Online (Sandbox Code Playgroud) 对此可能有一个简单的答案,只是不确定如何从我的搜索中取出它.
我在我的python代码中遵循PEP8,并且我正在使用OptionParser来编写我正在编写的脚本.为了防止行超过80,我在需要的地方使用反斜杠.
例如:
if __name__=='__main__':
usage = '%prog [options]\nWithout any options, will display 10 random \
users of each type.'
parser = OptionParser(usage)
Run Code Online (Sandbox Code Playgroud)
反斜杠后的缩进导致:
~$ ./er_usersearch -h
Usage: er_usersearch [options]
Without any options, will display 10 random users of each type.
Run Code Online (Sandbox Code Playgroud)
"随机"之后的差距让我感到困惑.我可以:
if __name__=='__main__':
usage = '%prog [options]\nWithout any options, will display 10 random \
users of each type.'
parser = OptionParser(usage)
Run Code Online (Sandbox Code Playgroud)
但这让我感到困扰.这看起来很傻:
if __name__=='__main__':
usage = ''.join(['%prog [options]\nWithout any options, will display',
' 10 random users of …Run Code Online (Sandbox Code Playgroud) 我经常gq用来包装代码......但是在字符串方面它并不是很聪明.例如,包装:
foo = bar("a b c d e f")
Run Code Online (Sandbox Code Playgroud)
可能导致:
foo = bar("a b c
d e f")
Run Code Online (Sandbox Code Playgroud)
显然,这并不像以下那样有用:
foo = bar("a b c " +
"d e f")
Run Code Online (Sandbox Code Playgroud)
将会.
有没有办法包装考虑到这一点的文本?