English 中文(简体)
如何在VIM的原始来源法中把长篇大论联系起来?
原标题:How to fold long docstrings in python source code in VIM?
  • 时间:2010-06-22 14:51:58
  •  标签:
  • python
  • vim

Does anybody know of a method, or perhaps a plugin, that will automatically fold long docstrings in Python? I have docstrings in my code that span several pages, so it is troublesome to keep paging through them. The other tricky part is that there is embedded python testing code in the docstrings, so that might make parsing them difficult. Note that I only need to automatically fold the entire docstring, regardless of what is in it.

最佳回答

这是一条 d子,但你可以通过 p子文档(<>条码>:百上千三联苯胺/乙ax/python.vim)找到所有合成物区域,用于三倍引星体(<条码>>/>和<条码>>>>查询”,并在发言结束前添加<条码>、关键词。 然后仅为平线文档设计, 倍增效应, 评注应当加以整理。

问题回答

I m不确定原始或自动化,但如果是您的类型zf/。 之后,你可以寻找一些东西,并且将紧接着下一个例子。 因此,在一份类似文件中(如果是...... cur):

def foo():
    """[]
    Some long docstring
    that takes up many
    lines
    """
    pass

www.un.org/Depts/DGACM/index_spanish.htm 看看2 先看一下最新的搜索线!。

如果你使用<条码>zf/”“[ENTER],它应将一切从目前的条线(行文开始)到次出现的<条码>“,即行文结束。

我知道这一底线自动化,但或许会有助于临时进行,或引导你走上实现自动化的正确道路。 See edit2 for a better search function,尽管我仍然不知道如何实现自动化。

希望这一帮助。

<<>Edit>/strong>:在必然结果中,您可查询任何以/">/__{-}”为“的示意图,尽管这还将在示意图中重新加入该守则。 为了寻找功能定义,然后进行演示,你可以使用<代码>/def/_.{-}”/_.{-}”,尽管这一突破是在示意图范围内进行的。

www.un.org/Depts/DGACM/index_spanish.htm Edit2:实际上,与reg鱼做些更多的游戏,导致我这样做:/def.{-}:/_s*”/_.{-}”,其中应发现任何功能,然后作指示。 检索def 随后是<代码>:,之后是一条新线和(或)白色空间,随后是>“>,之后是除下一个<代码>”外的任何几条线路“”,但始终确保第二三条插图是紧接一的。

阁下:

" folding
set foldmethod=indent

这将在每一个登革站自动翻翻一番,在座右铭上,这可转化为扼杀。 该公司经营“VERY VERY”冰。 把它当作审判。 以上答案是正确的,但需要一刀切(拉!)

我认为,我发现,通过试图说明如何在没有根本准入的情况下做同样的事情,对“@too_max_php”的答复稍有改进。 编辑《海因克斯区域定义》(,$VIMRUNTIME/syntax/python.vi~/.vim/ subsequently/syntax/python.vim,并编辑解决了我的问题。 兹在我关于<代码>~/vim/yon/syntax/python.vim的守则中:

syn region  docString1
       start=+[uU]=z(   |""")+ end="z1" keepend transparent fold
syn region  docString2
       start=+[uU]=[rR]z(   |""")+ end="z1" keepend transparent fold

现在,我可以操作<条码>:打成双倍方法。

PS: 初步想法的信贷到@too_max_php

您可使用<代码>:set raftmethod=marker /61/3marker="”“,我想。 我先对它进行了测试,但应该这样做。 翻标记的论据是开端标识。

几年前,我写了一幅精彩的画面,正好这样做,但从来不去出版。 I ve put it up as a gist ,但又把来文方搁置如下。 I ve还复制了以下功能:Sublime Text here

"
" Fold multi-line Python comments into one line.
"
" Also maps the "-" key to toggle expansion and <C-f> to toggle all folding.
"
setlocal foldmethod=syntax
setlocal foldtext=FoldText()
setlocal fillchars=

map <buffer> - za
map <buffer> <C-f> :call ToggleFold()<CR>

let b:folded = 1

hi Folded     gui=bold cterm=bold guifg=cyan ctermfg=cyan guibg=NONE ctermbg=NONE

function! ToggleFold()
  if b:folded == 0
    exec "normal! zM"
    let b:folded = 1
  else
    exec "normal! zR"
    let b:folded = 0
  endif
endfunction

function! s:Strip(string)
  return substitute(a:string,  ^[[:space:][:return:][:cntrl:]]+|[[:space:][:return:][:cntrl:]]+$ ,   ,   )
endfunction

" Extract the first line of a multi-line comment to use as the fold snippet
function! FoldText()
  let l:snippet = getline(v:foldstart)
  if len(s:Strip(l:snippet)) == 3
    let l:snippet = strpart(l:snippet, 1) . s:Strip(getline(v:foldstart + 1))
  endif
  return  +  . l:snippet .   ... 
endfunction




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签