Git Product home page Git Product logo

vim-codefmt's Introduction

Travis Build Status

codefmt is a utility for syntax-aware code formatting. It contains several built-in formatters, and allows new formatters to be registered by other plugins.

For details, see the executable documentation in the vroom/ directory or the helpfiles in the doc/ directory. The helpfiles are also available via :help codefmt if codefmt is installed (and helptags have been generated).

Commands

Use :FormatLines to format a range of lines or use :FormatCode to format the entire buffer.

Usage example

Before:

int foo(int * x) { return * x** x ; }

After running :FormatCode:

int foo(int* x) { return *x * *x; }

Installation

This example uses Vundle, whose plugin-adding command is Plugin.

" Add maktaba and codefmt to the runtimepath.
" (The latter must be installed before it can be used.)
Plugin 'google/vim-maktaba'
Plugin 'google/vim-codefmt'
" Also add Glaive, which is used to configure codefmt's maktaba flags. See
" `:help :Glaive` for usage.
Plugin 'google/vim-glaive'
" ...
call vundle#end()
" the glaive#Install() should go after the "call vundle#end()"
call glaive#Install()
" Optional: Enable codefmt's default mappings on the <Leader>= prefix.
Glaive codefmt plugin[mappings]

Make sure you have updated maktaba recently. Codefmt depends upon maktaba to register formatters.

Installing and configuring formatters

Codefmt defines several built-in formatters. The easiest way to see the list of available formatters is via tab completion: Type :FormatCode <TAB> in vim. Formatters that apply to the current filetype will be listed first.

To use a particular formatter, type :FormatCode FORMATTER-NAME. This will either format the current buffer using the selected formatter or show an error message with basic setup instructions for this formatter. Normally you will trigger formatters via key mappings and/or autocommand hooks. See vroom/main.vroom to learn more about formatting features, and see vroom/FORMATTER-NAME.vroom to learn more about usage for individual formatters.

Most formatters have some options available that can be configured via Glaive. You can get a quick view of all codefmt flags by executing :Glaive codefmt, or start typing flag names and use tab completion. See :help Glaive for usage details.

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.