Python的string-literal并置使多行字符串更容易编写,也更漂亮,但是当我缩进了四到五个缩进并且想要使用整行时(前导空格无关紧要),Vim的foldmethod=indent
就会崩溃。在
例如:
def getQuotation():
print "Fetching quotation from the absolutely useless function."
return ("Four score and seven years ago our fathers brought forth, "
"upon this continent, a new nation, conceived in liberty, and dedicated "
"to the proposition that \"all men are created equal\"")
应该这样折叠:
^{pr2}$但我得到的却是:
def getQuotation():
+-- 2 lines: print "Fetching quotation from the absolutely useless function."--
"upon this continent, a new nation, conceived in liberty, and dedicated "
"to the proposition that \"all men are created equal\"")
我尝试设置foldignore=\"
,但没有成功。Vim的help foldignore
提供了这样一个主题:
Used only when 'foldmethod' is "indent". Lines starting with characters in 'foldignore' will get their fold level from surrounding lines. White space is skipped before checking for this character.
有没有什么明显的东西我遗漏了,或者我将不得不求助于foldmethod=expr
,以缩进为基础,除了我自己的角盒?在
编辑:我至少取得了一些进展;事实证明,如果我在字符串和后面添加一个非空行,用set fdm=indent
刷新缩进,那么块就会按预期折叠。即使是一个空的注释(#
)也足够了。在
简而言之:你不能用
foldmethod=indent
来做这个,但是我发现了一些可以与foldmethod=expr
一起使用的东西,所以不需要重新设计轮子。看长答案。在长答案
只是简单回顾一下
foldmethod=indent
是如何工作的。。。在shiftwidth
foldlevel
由于文本在屏幕的边缘是对正的,任何涉及
shiftwidth
的内容最终都会被破坏,除非您像您那样对其进行修改。在我研究了几种不同的
.vimrc
配置,然后找到了可以工作的方法。对于比foldmethod=indent
更干净的解决方案,请将foldmethod=expr
与下面的~/.vimrc
一起使用。我在jneb's bitbucket python-fold repo找到的作为测试,我在您的示例中构建了更多的案例。。。在
在我的
~/.vimrc
底部使用python-fold可以得到:当我点击
zR
展开时:仅供参考,我使用Dmitry Vasiliev的^{} in
~/.vim/syntax/python.vim
中的python语法亮点。在我在下面复制了jneb的vim脚本,以防bitbucket回购消失。。。在
^{pr2}$
您可以将}提高了折叠速度。在
python-mode
与FastFold
一起使用。Python-mode
解决了很多折叠问题,{相关问题 更多 >
编程相关推荐