From 53c971b80232b9cba9a6b2de7dc3ee1c496fd902 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Mon, 3 Sep 2018 22:16:40 +0100 Subject: [PATCH] Use vim-coiled-snake instead of custom Python fold --- after/ftplugin/python.vim | 48 --------------------------------------- vimrc | 3 +++ 2 files changed, 3 insertions(+), 48 deletions(-) diff --git a/after/ftplugin/python.vim b/after/ftplugin/python.vim index b50b930..68da4dd 100644 --- a/after/ftplugin/python.vim +++ b/after/ftplugin/python.vim @@ -28,51 +28,3 @@ let g:python_highlight_all=1 " Mappings nnoremap K :YcmCompleter GetDoc - -" Set custom fold expression -setlocal foldmethod=expr -setlocal foldexpr=PythonFold(v:lnum) - -" Custom fold function greedyily matches following blank lines -function! PythonFold(lnum) - let l:line = getline(a:lnum) - " TODO: Folding breaks around method decorators: - " class Class(object): - " @property - " def method(self): - " pass - - " Blank lines, comments, and docstrings use previous fold level - if l:line =~ '^\(\s*\|#.*\|"\(""\)\=.*\)$' - return '=' - " Keywords beginning indented blocks start a fold - elseif l:line =~ '^\s*class\s\+\w*(\w*)\s*:\s*$' - \ || l:line =~ '^\s*def\s\+\w\+\s*(.*)\s*:\s*$' - \ || l:line =~ '^\s*if\s\+.*:\s*$' - \ || l:line =~ '^\s*elif\s\+.*:\s*$' - \ || l:line =~ '^\s*else\s*:\s*$' - \ || l:line =~ '^\s*for\s\+.*:\s*$' - \ || l:line =~ '^\s*while\s\+.*:\s*$' - \ || l:line =~ '^\s*try\s*:\s*$' - \ || l:line =~ '^\s*except\s*.*:\s*$' - return '>'.string((indent(a:lnum) / &shiftwidth) + 1) - " Opening curly braces, not in a string, add a fold level - elseif l:line =~ '{' && l:line !~ '}' && l:line !~ "'.*{.*'" && l:line !~ '".*{.*"' - return 'a1' - " Closing curly braces, not in a string, substract a fold level - elseif l:line =~ '}' && l:line !~ '{' && l:line !~ "'.*}.*'" && l:line !~ '".*}.*"' - return 's1' - " Opening square braces, not in a string, add a fold level - elseif l:line =~ '[' && l:line !~ ']' && l:line !~ "'.*[.*'" && l:line !~ '".*].*"' - return 'a1' - " Closing square braces, not in a string, substract a fold level - elseif l:line =~ ']' && l:line !~ '[' && l:line !~ "'.*].*'" && l:line !~ '".*[.*"' - return 's1' - " Calculate lines with a lower indent than the previous line - elseif indent(a:lnum) < indent(a:lnum - 1) - return string((indent(a:lnum) / &shiftwidth)) - endif - - " Finally all unmatched lines use fold level from previous line - return '=' -endfunction diff --git a/vimrc b/vimrc index 6df56d9..f380e64 100644 --- a/vimrc +++ b/vimrc @@ -171,6 +171,9 @@ let g:DoxygenToolkit_commentType = 'C++' let g:markdown_fenced_languages = \ ['cpp', 'c', 'cmake', 'sh', 'vim', 'python', 'yaml'] +" Python folding +Plug 'kalekundert/vim-coiled-snake' + " Enable builtin syntax folding let g:xml_syntax_folding = 1 let g:sh_fold_enabled = 1