All Projects → google → Vim Codefmt

google / Vim Codefmt

Licence: apache-2.0

Projects that are alternatives of or similar to Vim Codefmt

Fantomas
FSharp source code formatter
Stars: ✭ 475 (-45.4%)
Mutual labels:  formatter
Dprint
Pluggable and configurable code formatting platform written in Rust.
Stars: ✭ 610 (-29.89%)
Mutual labels:  formatter
Go Money
Go implementation of Fowler's Money pattern
Stars: ✭ 887 (+1.95%)
Mutual labels:  formatter
Globalize
A JavaScript library for internationalization and localization that leverages the official Unicode CLDR JSON data
Stars: ✭ 4,612 (+430.11%)
Mutual labels:  formatter
Buildtools
A bazel BUILD file formatter and editor
Stars: ✭ 538 (-38.16%)
Mutual labels:  formatter
Prettier Atom
An atom package for the prettier formatter.
Stars: ✭ 750 (-13.79%)
Mutual labels:  formatter
Prettier Eslint Cli
CLI for prettier-eslint
Stars: ✭ 451 (-48.16%)
Mutual labels:  formatter
Vim Clang Format
Vim plugin for clang-format, a formatter for C, C++, Obj-C, Java, JavaScript, TypeScript and ProtoBuf.
Stars: ✭ 837 (-3.79%)
Mutual labels:  formatter
Ormolu
A formatter for Haskell source code
Stars: ✭ 592 (-31.95%)
Mutual labels:  formatter
Online Markdown
A online markdown converter specially for Wechat Public formatting.
Stars: ✭ 812 (-6.67%)
Mutual labels:  formatter
Input Mask Ios
User input masking library repo.
Stars: ✭ 494 (-43.22%)
Mutual labels:  formatter
Maskara
A simple way to format text fields without getting affected by input filters
Stars: ✭ 515 (-40.8%)
Mutual labels:  formatter
Sql Formatter
A whitespace formatter for different query languages
Stars: ✭ 779 (-10.46%)
Mutual labels:  formatter
Sublime Jsfmt
jsfmt plugin for Sublime Text
Stars: ✭ 480 (-44.83%)
Mutual labels:  formatter
Translatedjs
Internationalization and localization for JavaScript and Node.js
Stars: ✭ 17 (-98.05%)
Mutual labels:  formatter
Unibeautify
One Beautifier to rule them all, One Beautifier to clean them, One Beautifier to bring them all and in the darkness sheen them
Stars: ✭ 466 (-46.44%)
Mutual labels:  formatter
Rufo
The Ruby Formatter
Stars: ✭ 691 (-20.57%)
Mutual labels:  formatter
Vim Gofmt
Formats Go source code asynchronously with multiple Go formatters.
Stars: ✭ 11 (-98.74%)
Mutual labels:  formatter
Moment.php
Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
Stars: ✭ 900 (+3.45%)
Mutual labels:  formatter
Headwind
An opinionated Tailwind CSS class sorter built for Visual Studio Code
Stars: ✭ 789 (-9.31%)
Mutual labels:  formatter

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).

Supported File-types

  • Bazel BUILD files (buildifier)
  • C, C++ (clang-format)
  • Clojure (zprint)
  • CSS, Sass, SCSS, Less (js-beautify)
  • Dart (dartfmt)
  • Fish (fish_indent)
  • Go (gofmt)
  • GN (gn)
  • HTML (js-beautify)
  • Java (google-java-format or clang-format)
  • JavaScript (clang-format or prettier)
  • JSON (js-beautify)
  • Proto (clang-format)
  • Python (Autopep8, Black, or YAPF)
  • Rust (rustfmt)
  • TypeScript (clang-format)
  • Shell (shfmt)
  • Vue (prettier)
  • Nix (nixpkgs-fmt)

Commands

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

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]
Glaive codefmt google_java_executable="java -jar /path/to/google-java-format-VERSION-all-deps.jar"

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

Autoformatting

Want to just sit back and let autoformat happen automatically? Add this to your vimrc (or any subset):

augroup autoformat_settings
  autocmd FileType bzl AutoFormatBuffer buildifier
  autocmd FileType c,cpp,proto,javascript,arduino AutoFormatBuffer clang-format
  autocmd FileType dart AutoFormatBuffer dartfmt
  autocmd FileType go AutoFormatBuffer gofmt
  autocmd FileType gn AutoFormatBuffer gn
  autocmd FileType html,css,sass,scss,less,json AutoFormatBuffer js-beautify
  autocmd FileType java AutoFormatBuffer google-java-format
  autocmd FileType python AutoFormatBuffer yapf
  " Alternative: autocmd FileType python AutoFormatBuffer autopep8
  autocmd FileType rust AutoFormatBuffer rustfmt
  autocmd FileType vue AutoFormatBuffer prettier
augroup END

Configuring 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.

Installing 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.

Creating a New Formatter

Assume a filetype myft and a formatter called MyFormatter. Our detailed guide to creating a formatter lives here.

  • Create an issue for your new formatter and discuss!

  • Create a new file in autoload/codefmt/myformatter.vim See `autoload/codefmt/buildifier.vim for an example. This is where all the logic for formatting goes.

  • Register the formatter in plugin/register.vim with:

    call s:registry.AddExtension(codefmt#myformatter#GetFormatter())
    
  • Create a flag in instant/flags.vim

    ""
    " The path to the buildifier executable.
    call s:plugin.Flag('myformatter_executable', 'myformatter')
    
  • Create a vroom test named vroom/myformatter.vroom to ensure your formatter works properly.

  • Update the README.md to mention your new filetype!

That's it! Of course, the complicated step is in the details of myformatter.vim.

// TODO(kashomon): Create a worked example formatter.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].