{"id":13419942,"url":"https://github.com/rhysd/vim-clang-format","last_synced_at":"2025-05-16T11:03:47.169Z","repository":{"id":10115956,"uuid":"12183517","full_name":"rhysd/vim-clang-format","owner":"rhysd","description":"Vim plugin for clang-format, a formatter for C, C++, Obj-C, Java, JavaScript, and so on.","archived":false,"fork":false,"pushed_at":"2022-01-26T12:29:31.000Z","size":221,"stargazers_count":1093,"open_issues_count":43,"forks_count":123,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-04-09T05:04:48.478Z","etag":null,"topics":["clang","clang-format","formatter","vim","vim-plugin"],"latest_commit_sha":null,"homepage":"http://clang.llvm.org/docs/ClangFormat.html","language":"Vim script","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"Yixiaohan/show-me-the-code","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rhysd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-08-17T18:31:56.000Z","updated_at":"2025-04-06T19:54:21.000Z","dependencies_parsed_at":"2022-08-01T08:09:52.971Z","dependency_job_id":null,"html_url":"https://github.com/rhysd/vim-clang-format","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Fvim-clang-format","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Fvim-clang-format/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Fvim-clang-format/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhysd%2Fvim-clang-format/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rhysd","download_url":"https://codeload.github.com/rhysd/vim-clang-format/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254518383,"owners_count":22084374,"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","clang-format","formatter","vim","vim-plugin"],"created_at":"2024-07-30T22:01:23.242Z","updated_at":"2025-05-16T11:03:47.145Z","avatar_url":"https://github.com/rhysd.png","language":"Vim script","funding_links":[],"categories":["Vim Script"],"sub_categories":[],"readme":"Format your C family code\n=======================================\n[![CI](https://github.com/rhysd/vim-clang-format/actions/workflows/ci.yml/badge.svg)](https://github.com/rhysd/vim-clang-format/actions/workflows/ci.yml)\n\nThis plugin formats your code with specific coding style using [clang-format](http://clang.llvm.org/docs/ClangFormat.html).\n\nAutomatic formatting is provided for the following languages by default:\n\n- C\n- C++\n- Objective-C\n- JavaScript\n- Java\n- TypeScript\n- Protobuf\n- Cuda\n- Vala\n\n## Screenshot\n\n![Screenshot](https://raw.githubusercontent.com/rhysd/ss/master/vim-clang-format/main.gif)\n\n## Requirements\n\n- `clang-format` command (**3.4 or later**), which is bundled in Clang extra tools\n- [vim-operator-user](https://github.com/kana/vim-operator-user)(highly recommended)\n- [vimproc.vim](https://github.com/Shougo/vimproc.vim)(recommended in Windows)\n\n## Installation\n\nCopy `plugin`, `doc` and `autoload` directories into your `~/.vim` or use `:packadd` in Vim8. Or please use your favorite plugin manager to install this plugin. I recommend latter.\n\n## Usage\n\n`:ClangFormat` command is available.\nIf you use it in normal mode, the whole code will be formatted. If you use it in visual mode, the selected code will be formatted.\nIt is more convenient to map `:ClangFormat` to your favorite key mapping in normal mode and visual mode.\n\nIf you install [vim-operator-user](https://github.com/kana/vim-operator-user) in advance, you can also map `\u003cPlug\u003e(operator-clang-format)` to your favorite key bind.\n\n`:ClangFormatAutoToggle` command toggles the auto formatting on buffer write.\n`:ClangFormatAutoEnable` command enables the auto formatting on buffer write. Useful for automatically enabling the auto format through a vimrc. `:ClangFormatAutoDisable` turns it off.\n\n## What is the difference from `clang-format.py`?\n\n`clang-format.py` is Python script to use clang-format from Vim, which is installed with clang-format.\nThe usage is [here](http://clang.llvm.org/docs/ClangFormat.html#vim-integration).\nAgainst `clang-format.py`, vim-clang-format has below advantages.\n\n- Style options are highly customizable in `.vimrc`. `clang-format.py` requires `.clang-format` file to customize a style.\n- vim-clang-format provides an operator mapping.\n- vim-clang-format doesn't need python interface.\n\nIn short, vim-clang-format has better Vim integration than `clang-format.py`.\n\n## Customization\n\nYou can customize formatting using some variables.\n\n- `g:clang_format#code_style`\n\n`g:clang_format#code_style` is a base style.\n`llvm`, `google`, `chromium`, `mozilla` is supported.\nThe default value is `google`.\n\n- `g:clang_format#style_options`\n\nCoding style options as dictionary.\n\nAn example is below:\n\n```vim\nlet g:clang_format#style_options = {\n            \\ \"AccessModifierOffset\" : -4,\n            \\ \"AllowShortIfStatementsOnASingleLine\" : \"true\",\n            \\ \"AlwaysBreakTemplateDeclarations\" : \"true\",\n            \\ \"Standard\" : \"C++11\",\n            \\ \"BreakBeforeBraces\" : \"Stroustrup\"}\n```\n\nFor config information, execute `clang-format -dump-config` command.\n\n- `g:clang_format#command`\n\nName of `clang-format`. If the name of command is not `clang-format`\nor you want to specify a command by absolute path, set this variable.\nDefault value is `clang-format`.\n\n- `g:clang_format#extra_args`\n\nYou can specify more extra options in `g:clang_format#extra_args` as String or List of String.\n\n- `g:clang_format#detect_style_file`\n\nWhen this variable's value is `1`, vim-clang-format automatically detects the style file like\n`.clang-format` or `_clang-format` and applies the style to formatting.\n\n- `g:clang_format#auto_format`\n\nWhen the value is 1, a current buffer is automatically formatted on saving the buffer.\nFormatting is executed on `BufWritePre` event.\n\n- `g:clang_format#auto_format_on_insert_leave`\n\nWhen the value is 1, inserted lines are automatically formatted on leaving insert mode.\nFormatting is executed on `InsertLeave` event.\n\n- `g:clang_format#auto_formatexpr`\n\nWhen the value is 1, `formatexpr` option is set by vim-clang-format automatically in C, C++ and ObjC codes.\nVim's format mappings (e.g. `gq`) get to use `clang-format` to format. This\noption is not comptabile with Vim's `textwidth` feature. You must set\n`textwidth` to `0` when the `formatexpr` is set.\n\n- `g:clang_format#auto_filetypes`\n\nList of file types to which `g:clang_format#auto_format`, `g:clang_format#auto_format_on_insert_leave`,\nand `g:clang_format#auto_formatexpr` should be applied.\nThe default value is `[\"c\", \"cpp\", \"objc\", \"java\", \"javascript\", \"typescript\", \"proto\", \"arduino\"]`.\n\n- `g:clang_format#enable_fallback_style`\n\nWhen the value is 0, `-fallback-style=none` option is added on executing clang-format command.\nIt means that vim-clang-format does nothing when `.clang-format` is not found.\nThe default value is 1.\n\n## Vimrc Example\n\n```vim\nlet g:clang_format#style_options = {\n            \\ \"AccessModifierOffset\" : -4,\n            \\ \"AllowShortIfStatementsOnASingleLine\" : \"true\",\n            \\ \"AlwaysBreakTemplateDeclarations\" : \"true\",\n            \\ \"Standard\" : \"C++11\"}\n\n\" map to \u003cLeader\u003ecf in C++ code\nautocmd FileType c,cpp,objc nnoremap \u003cbuffer\u003e\u003cLeader\u003ecf :\u003cC-u\u003eClangFormat\u003cCR\u003e\nautocmd FileType c,cpp,objc vnoremap \u003cbuffer\u003e\u003cLeader\u003ecf :ClangFormat\u003cCR\u003e\n\" if you install vim-operator-user\nautocmd FileType c,cpp,objc map \u003cbuffer\u003e\u003cLeader\u003ex \u003cPlug\u003e(operator-clang-format)\n\" Toggle auto formatting:\nnmap \u003cLeader\u003eC :ClangFormatAutoToggle\u003cCR\u003e\n```\n\n### Auto-enabling auto-formatting\n\n```vim\nautocmd FileType c ClangFormatAutoEnable\n```\n\n## For More Information\n\n```\n$ clang-format -help\n```\n\n```\n$ clang-format -dump-config\n```\n\nclang-format's documentation and API documentation is useful in some cases.\nIn particular, the following link is useful to know the information of a key and its value of a style setting.\n[CLANG-FORMAT STYLE OPTIONS](http://clang.llvm.org/docs/ClangFormatStyleOptions.html)\n\n## License\n\n    The MIT License (MIT)\n\n    Copyright (c) 2013-2021 rhysd\n\n    Permission is hereby granted, free of charge, to any person obtaining a copy\n    of this software and associated documentation files (the \"Software\"), to deal\n    in the Software without restriction, including without limitation the rights\n    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n    copies of the Software, and to permit persons to whom the Software is\n    furnished to do so, subject to the following conditions:\n\n    The above copyright notice and this permission notice shall be included in\n    all copies or substantial portions of the Software.\n\n    THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n    THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhysd%2Fvim-clang-format","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frhysd%2Fvim-clang-format","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhysd%2Fvim-clang-format/lists"}