Code Monkey home page Code Monkey logo

formpy.vim's Introduction

formpy.vim

Provides YAPF vim integration in the same way as formative.vim integrates clang-format.

The plugin supports the same set of actions as formative.vim, for example:

<C-k>2j   - YAPF 2 lines downwards
<C-k>ap   - YAPF around the current paragraph
<C-k>/foo - YAPF from the current line until the first match of 'foo'

The only limitations come from python's syntax, so a valid formative.vim action:

<C-k>iB   - ClangFormat "inner Block"

would still pass the block to YAPF, but will have slightly different range.

Formpy-Formative Integration

formative.vim is great, in fact it is so good, that I had to write this plugin. Once you start using formative.vim, there is no way back, you have to have formatting done automatically for you. And it is XXI century, the time of manually inserting spaces (no tabs, no!) is over. The problem arises, when you get used to the mappings provided by formative.vim and want to have the same mappings working in python. By default, whichever plugin is loaded last will, be responsible for formatting, regardless of the buffer's filetype. The solution provided here, is to have the desired mappings redefined in after-directory. It provides the mappings, for the followings file types: python, c and cpp.

An example of two buffers (cpp and py) calling into formative.vim and formpy respectively.

Requirements

Unlike formative.vim, formpy comes with its own python runner, so ther is no need to point it to any external files. However, you will have to make sure that YAPF is installed and available on the path of your system. Formpy also requires vim compiled with python support.

Key Bindings

As per formative.vim <C-k> is set as a default 'leader' key in the plugin. Follow this key with whichever motion or text object you like, as in the examples above. It can be customised.

Special Bindings

Again, as per formative.vim, 'quick' YAPF binding is provided via g:formpy_line_key. This works on the current line alone. Its default mapping is <C-k>k, which is designed to emulate vim's c -> cc, d -> dd line-wise operations. <C-k>u is used to invoke YAPF on the whole file, and can be reset with g:fmtv_clang_format_file_key.

Installation

Add the following to your .vimrc:

Plug 'jchlanda/formpy.vim'

Source your .vimrc and run:

:PlugInstall

Add the following to your .vimrc:

Plugin 'jchlanda/formpy.vim'

Source your .vimrc and run:

:PluginInstall

The plugin defines its own help tags, please remember to run: :helptags and :help formpy.

Customisation

All of the variables used by formpy to construct specific key mappings can be overridden, please see:

let g:formpy_nor_key  = <C-woof>
let g:formpy_vis_key  = <C-woof>
let g:formpy_ins_key  = <C-woof>
let g:formpy_line_key = <C-woof>
let g:formpy_file_key = <C-woof>

All of the variables used by formpy to construct specific key mappings can be overridden, please see:

YAPF allows for different formatting styles to be used, formpy exposes this functionality through g:formpy_style option. It can be set to either the name of the desired formatting style (for example pep8 or goole), or to the fully qualified file name containing style settings. For full details on the available formatting options please run: yapf --help or yapf --style-help.

A sample formatting style file is included here.

Formpy defaults to: pep. To change it:

let g:formpy_style = /path/to/your_style.yapf

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.