What is the recommended way to use Vim folding for Python code

后端 未结 11 2072
自闭症患者
自闭症患者 2020-12-22 16:33

I am interested in enabling code folding in Vim for Python code. I have noticed multiple ways to do so.

Does anyone have a preferred way to do Python code folding in

11条回答
  •  -上瘾入骨i
    2020-12-22 17:03

    Python is well suited for folding on indent, bit for writing my own code I use markers as they can crunch a document down the way you want it and can serve as a kind of a table of contents. I have this in my vimrc to flip between the two when I'm viewing someone elses code.

    #Toggle fold methods \fo
    let g:FoldMethod = 0
    map fo :call ToggleFold()
    fun! ToggleFold()
        if g:FoldMethod == 0
            exe 'set foldmethod=indent'
            let g:FoldMethod = 1
        else
            exe 'set foldmethod=marker'
            let g:FoldMethod = 0
        endif
    endfun
    #Add markers (trigger on class Foo line)
    nnoremap ,f2 ^wywO#0 {{{2
    nnoremap ,f3 ^wywO#0 {{{3 
    nnoremap ,f4 ^wywO#0 {{{4
    nnoremap ,f1 ^wywO#0 {{{1
    

提交回复
热议问题