abstract
| - Unfortunately, the Python syntax file provided with Vim does not contain folding information. You can however create a custom Python syntax script that folds def and class regions. To make this work, copy file python.vim provided with Vim, and modify the copy. In Vim, the file that needs to be copied is $VIMRUNTIME/syntax/python.vim, and the directory $VIMRUNTIME can be determined by entering the following command in Vim: :echo $VIMRUNTIME For example, on a Unix system the source file might be /usr/share/vim/vim73/syntax/python.vim, while on a Windows system it might be C:\Program Files\Vim\Vim73\syntax\python.vim. The python.vim file should be copied to the following directory (you need to create any directories that are not present on your system):
* ~/.vim/after/syntax on Unix-based systems; or
* $HOME/vimfiles/after/syntax on Windows systems (use :echo $HOME to determine your $HOME directory) Open the copied file in Vim and change it like this: Find the line that looks like: syn keyword pythonStatement nextgroup=pythonFunction skipwhite and delete it. And also find these lines: if version < 600 syntax clear elseif exists("b:current_syntax") finish endif and change them to: syntax clear Additionally, you should create file after/ftplugin/python.vim which sets up folding for Python files. In that file, write: setlocal foldmethod=syntax setlocal foldtext=substitute(getline(v:foldstart),'\ ','\ \ \ \ ','g') This will enable syntax folding for Python scripts. Additional settings for Python files can also be in after/ftplugin/python.vim (see indenting source code for an example). If the settings from this file do not work, you need to set up the filetype settings in your vimrc (see [help :filetype-plugin-on]).
|