GithubHelp home page GithubHelp logo

msenyor / simpylfold Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tmhedberg/simpylfold

0.0 2.0 0.0 42 KB

No-BS Python code folding for Vim

License: BSD 3-Clause "New" or "Revised" License

Vim Script 100.00%

simpylfold's Introduction

SimpylFold

Because of its reliance on significant whitespace rather than explicit block delimiters, properly folding Python code can be tricky. The Python syntax definition that comes bundled with Vim doesn't contain any fold directives at all, and the simplest workaround is to :set foldmethod=indent, which usually ends up folding a lot more than you really want it to.

There's no shortage of Vim plugins for improved Python folding, but most seem to suffer from cobbled-together algorithms with bizarre, intractable bugs in the corner cases. SimpylFold aims to be exactly what its name suggests: simple, correct folding for Python. It's nothing more than it needs to be: it properly folds class and function/method definitions, and leaves your loops and conditional blocks untouched. There's no BS involved: no screwing around with unrelated options (which several of the other plugins do), no choice of algorithms to scratch your head over (because there's only one that's correct); it just works, simply.

Installation

Pathogen

If you're using Pathogen and Git to manage your Vim plugins (highly recommended), you can just

cd ~/.vim
git submodule add https://github.com/tmhedberg/SimpylFold.git bundle/SimpylFold
git submodule init

and you're good to go.

Vundle

If you use Vundle then put in your .vimrc:

Plugin 'tmhedberg/SimpylFold'

and then launch vim and run :PluginInstall.

NeoBundle

If you use NeoBundle then put in your .vimrc:

NeoBundle 'tmhedberg/SimpylFold'

and then launch vim and run :NeoBundleInstall.

Manually

If you insist on doing this manually, then just clone this repo somewhere or just grab the tarball, and drop the plugin file into your ~/.vim/ftplugin/python.

Configuration

No configuration is necessary. However, if you want to enable previewing of your folded classes' and functions' docstrings in the fold text, add the following to your .vimrc:

let g:SimpylFold_docstring_preview = 1

And if you don't want to see your docstrings folded, add this:

let g:SimpylFold_fold_docstring = 0

And if you don't want to see your imports folded, add this:

let g:SimpylFold_fold_import = 0

In order for SimpylFold to be properly loaded in certain cases, you'll have to add lines like the following to your .vimrc (see issue #27):

autocmd BufWinEnter *.py setlocal foldexpr=SimpylFold(v:lnum) foldmethod=expr
autocmd BufWinLeave *.py setlocal foldexpr< foldmethod<

If you have the above options set to different values anywhere (e.g. setting foldmethod=syntax in .vimrc, SimpylFold won't work properly.

Usage

SimpylFold doesn't define any custom commands. Just use Vim's built-in folding commands to expand and collapse folds. The most basic commands are zc to close a fold and zo to open one. See :help fold-commands for full documentation.

Bugs

If you find any bugs, please report them and/or submit pull requests on Github! Simple is nice, but simple and correct is much better.

Happy hacking!

simpylfold's People

Contributors

tmhedberg avatar yoriksar avatar sotlampr avatar tmmsartor avatar anntzer avatar asher256 avatar fruglemonkey avatar pmav99 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.