Home

Awesome

Coiled Snake: Python Folding for Vim

Coiled Snake is a vim plugin that provides automatic folding of python code. Its priorities are: (i) to make folds that are satisfyingly compact, (ii) to be attractive and unobtrusive, (iii) to be robust to any kind of style or formatting, and (iv) to be highly configurable. Here's what it looks like in action:

<p><a href="https://asciinema.org/a/234369?autoplay=1"> <img src="https://asciinema.org/a/234369.png" width="500"/> </a></p>

A couple features are worth drawing attention to:

Installation

Coiled Snake is compatible with both vim>=7.4 and neovim, and can be installed using any of the plugin management tools out there. I recommend also installing the FastFold plugin, since I find that it makes folding more responsive and less finicky, but it's not required.

pathogen

Clone this repository into your .vim/bundle directory:

cd ~/.vim/bundle
git clone git://github.com/kalekundert/vim-coiled-snake.git
git clone git://github.com/Konfekt/FastFold

vim-plug

Put the following line(s) in the call plug#begin() section of your .vimrc file:

Plug 'kalekundert/vim-coiled-snake'
Plug 'Konfekt/FastFold'

Vim8 native plugins

Clone the repository into .vim/pack/*/start:

mkdir -p ~/.vim/pack/git-plugins/start
cd ~/.vim/pack/git-plugins/start
git clone git://github.com/kalekundert/vim-coiled-snake.git

Note that you can name the directories in .vim/pack/ whatever you like, so the git-plugins name in the snippet above is just an example. Also be sure to enable the following option in your .vimrc file::

filetype plugin indent on

Usage

Coiled Snake works with all the standard folding commands. See :help fold-commands if you're not familiar, but below are the commands I use most frequently:

You can prevent Coiled Snake from folding a line that it otherwise would by putting a # at the end of said line. For example, the following function would not be folded:

def not_worth_folding(): #
    return 42

Configuration

No configuration is necessary, but the following options are available:

Troubleshooting

Contributing

Bug reports and pull requests are welcome. I'm especially interested to hear about cases where the folding algorithm produces goofy results, since it's hard to encounter every corner case.