{"id":13898924,"url":"https://github.com/google/vim-codefmt","last_synced_at":"2025-07-17T16:31:21.203Z","repository":{"id":26103027,"uuid":"29547192","full_name":"google/vim-codefmt","owner":"google","description":"Vim plugin for syntax-aware code formatting","archived":false,"fork":false,"pushed_at":"2024-08-31T16:39:54.000Z","size":316,"stargazers_count":1114,"open_issues_count":45,"forks_count":107,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-04-19T22:27:43.629Z","etag":null,"topics":["clang-format","formatter","js-beautify","vim"],"latest_commit_sha":null,"homepage":"","language":"Vim Script","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/google.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-01-20T19:16:44.000Z","updated_at":"2025-04-11T06:12:43.000Z","dependencies_parsed_at":"2023-11-24T06:27:34.442Z","dependency_job_id":"dc5eae46-7bad-4386-957d-ae5ca522448b","html_url":"https://github.com/google/vim-codefmt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/google/vim-codefmt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fvim-codefmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fvim-codefmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fvim-codefmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fvim-codefmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/google","download_url":"https://codeload.github.com/google/vim-codefmt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google%2Fvim-codefmt/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265629946,"owners_count":23801494,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clang-format","formatter","js-beautify","vim"],"created_at":"2024-08-06T18:04:32.391Z","updated_at":"2025-07-17T16:31:20.931Z","avatar_url":"https://github.com/google.png","language":"Vim Script","funding_links":[],"categories":["Vim Script"],"sub_categories":[],"readme":"[![Travis Build Status](https://travis-ci.org/google/vim-codefmt.svg?branch=master)](https://travis-ci.org/google/vim-codefmt)\n\ncodefmt is a utility for syntax-aware code formatting. It contains several\nbuilt-in formatters, and allows new formatters to be registered by other\nplugins.\n\nFor details, see the executable documentation in the `vroom/` directory or the\nhelpfiles in the `doc/` directory. The helpfiles are also available via `:help\ncodefmt` if codefmt is installed (and helptags have been generated).\n\n# Supported File-types\n\n*   [Bazel](https://www.github.com/bazelbuild/bazel) BUILD files (buildifier)\n*   C, C++ (clang-format)\n*   [Clojure](https://clojure.org/)\n    ([zprint](https://github.com/kkinnear/zprint),\n    [cljstyle](https://github.com/greglook/cljstyle))\n*   CSS, Sass, SCSS, Less (js-beautify, prettier)\n*   Dart (dartfmt)\n*   Elixir ([`mix format`](https://hexdocs.pm/mix/main/Mix.Tasks.Format.html))\n*   Fish\n    ([fish_indent](https://fishshell.com/docs/current/commands.html#fish_indent))\n*   [GN](https://www.chromium.org/developers/gn-build-configuration) (gn)\n*   Go (gofmt)\n*   Haskell ([ormolu](https://github.com/tweag/ormolu))\n*   HTML (js-beautify, prettier)\n*   Java (google-java-format or clang-format)\n*   JavaScript (clang-format, js-beautify, or [prettier](https://prettier.io))\n*   JSON (js-beautify)\n*   Jsonnet ([jsonnetfmt](https://jsonnet.org/learning/tools.html))\n*   Julia ([JuliaFormatter](https://github.com/domluna/JuliaFormatter.jl))\n*   Kotlin ([ktfmt](https://github.com/facebookincubator/ktfmt))\n*   Lua\n    ([FormatterFiveOne](https://luarocks.org/modules/ElPiloto/formatterfiveone))\n*   Markdown (prettier)\n*   Nix (nixpkgs-fmt)\n*   OCaml ([ocamlformat](https://github.com/ocaml-ppx/ocamlformat))\n*   Protocol Buffers (clang-format)\n*   Python (Autopep8, Black, isort, Ruff, or YAPF)\n*   Ruby ([rubocop](https://rubocop.org))\n*   Rust ([rustfmt](https://github.com/rust-lang/rustfmt))\n*   Shell (shfmt)\n*   Swift ([swift-format](https://github.com/apple/swift-format))\n*   TypeScript (clang-format)\n*   [Vue](http://vuejs.org) (prettier)\n\n# Commands\n\nUse `:FormatLines` to format a range of lines or use `:FormatCode` to format the\nentire buffer. Use `:NoAutoFormatBuffer` to disable current buffer formatting.\n\n# Usage example\n\nBefore:\n\n```cpp\nint foo(int * x) { return * x** x ; }\n```\n\nAfter running `:FormatCode`:\n\n```cpp\nint foo(int* x) { return *x * *x; }\n```\n\n# Installation\n\nThis example uses [Vundle](https://github.com/gmarik/Vundle.vim), whose\nplugin-adding command is `Plugin`.\n\n```vim\n\" Add maktaba and codefmt to the runtimepath.\n\" (The latter must be installed before it can be used.)\nPlugin 'google/vim-maktaba'\nPlugin 'google/vim-codefmt'\n\" Also add Glaive, which is used to configure codefmt's maktaba flags. See\n\" `:help :Glaive` for usage.\nPlugin 'google/vim-glaive'\n\" ...\ncall vundle#end()\n\" the glaive#Install() should go after the \"call vundle#end()\"\ncall glaive#Install()\n\" Optional: Enable codefmt's default mappings on the \u003cLeader\u003e= prefix.\nGlaive codefmt plugin[mappings]\nGlaive codefmt google_java_executable=\"java -jar /path/to/google-java-format-VERSION-all-deps.jar\"\n```\n\nMake sure you have updated maktaba recently. Codefmt depends upon maktaba to\nregister formatters.\n\n# Autoformatting\n\nWant to just sit back and let autoformat happen automatically? Add this to your\n`vimrc` (or any subset):\n\n```vim\naugroup autoformat_settings\n  autocmd FileType bzl AutoFormatBuffer buildifier\n  autocmd FileType c,cpp,proto,javascript,typescript,arduino AutoFormatBuffer clang-format\n  autocmd FileType clojure AutoFormatBuffer cljstyle\n  autocmd FileType dart AutoFormatBuffer dartfmt\n  autocmd FileType elixir,eelixir,heex AutoFormatBuffer mixformat\n  autocmd FileType fish AutoFormatBuffer fish_indent\n  autocmd FileType gn AutoFormatBuffer gn\n  autocmd FileType go AutoFormatBuffer gofmt\n  autocmd FileType haskell AutoFormatBuffer ormolu\n  \" Alternative for web languages: prettier\n  autocmd FileType html,css,sass,scss,less,json AutoFormatBuffer js-beautify\n  autocmd FileType java AutoFormatBuffer google-java-format\n  autocmd FileType jsonnet AutoFormatBuffer jsonnetfmt\n  autocmd FileType julia AutoFormatBuffer JuliaFormatter\n  autocmd FileType kotlin AutoFormatBuffer ktfmt\n  autocmd FileType lua AutoFormatBuffer luaformatterfiveone\n  autocmd FileType markdown AutoFormatBuffer prettier\n  autocmd FileType ocaml AutoFormatBuffer ocamlformat\n  autocmd FileType python AutoFormatBuffer yapf\n  \" Alternative: autocmd FileType python AutoFormatBuffer autopep8\n  autocmd FileType ruby AutoFormatBuffer rubocop\n  autocmd FileType rust AutoFormatBuffer rustfmt\n  autocmd FileType swift AutoFormatBuffer swift-format\n  autocmd FileType vue AutoFormatBuffer prettier\naugroup END\n```\n\n# Configuring formatters\n\nMost formatters have some options available that can be configured via\n[Glaive](https://www.github.com/google/vim-glaive) You can get a quick view of\nall codefmt flags by executing `:Glaive codefmt`, or start typing flag names and\nuse tab completion. See `:help Glaive` for usage details.\n\n# Installing formatters\n\nCodefmt defines several built-in formatters. The easiest way to see the list of\navailable formatters is via tab completion: Type `:FormatCode \u003cTAB\u003e` in vim.\nFormatters that apply to the current filetype will be listed first.\n\nTo use a particular formatter, type `:FormatCode FORMATTER-NAME`. This will\neither format the current buffer using the selected formatter or show an error\nmessage with basic setup instructions for this formatter. Normally you will\ntrigger formatters via key mappings and/or autocommand hooks. See\nvroom/main.vroom to learn more about formatting features, and see\nvroom/FORMATTER-NAME.vroom to learn more about usage for individual formatters.\n\n## Creating a New Formatter\n\nAssume a filetype `myft` and a formatter called `MyFormatter`. Our detailed\nguide to creating a formatter\n[lives here](https://github.com/google/vim-codefmt/wiki/Formatter-Integration-Guide).\n\n*   Create an issue for your new formatter and discuss!\n\n*   Create a new file in `autoload/codefmt/myformatter.vim` See\n    `autoload/codefmt/buildifier.vim for an example. This is where all the logic\n    for formatting goes.\n\n*   Register the formatter in [plugin/register.vim](plugin/register.vim) with:\n\n    ```vim\n    call s:registry.AddExtension(codefmt#myformatter#GetFormatter())\n    ```\n\n*   Create a flag in [instant/flags.vim](instant/flags.vim)\n\n    ```vim\n    \"\"\n    \" The path to the buildifier executable.\n    call s:plugin.Flag('myformatter_executable', 'myformatter')\n    ```\n\n*   Create a [vroom](https://github.com/google/vroom) test named\n    `vroom/myformatter.vroom` to ensure your formatter works properly.\n\n*   Update the README.md to mention your new filetype!\n\nThat's it! Of course, the complicated step is in the details of\n`myformatter.vim`.\n\n// TODO(kashomon): Create a worked example formatter.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle%2Fvim-codefmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoogle%2Fvim-codefmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle%2Fvim-codefmt/lists"}