A C++ code formatter based on Clang Format, for beautiful code with minimal effort in Sublime Text 3
- Total 6K
- Win 2K
- OS X 2K
- Linux 2K
|Aug 28||Aug 27||Aug 26||Aug 25||Aug 24||Aug 23||Aug 22||Aug 21||Aug 20||Aug 19||Aug 18||Aug 17||Aug 16||Aug 15||Aug 14||Aug 13||Aug 12||Aug 11||Aug 10||Aug 9||Aug 8||Aug 7||Aug 6||Aug 5||Aug 4||Aug 3||Aug 2||Aug 1||Jul 31||Jul 30||Jul 29||Jul 28||Jul 27||Jul 26||Jul 25||Jul 24||Jul 23||Jul 22||Jul 21||Jul 20||Jul 19||Jul 18||Jul 17||Jul 16||Jul 15||Jul 14|
What it does
Clang-format is a tool for re-formatting C++, built on LLVM. This is a package that allows you to run it easily from within Sublime Text.
In this package, we provide an alternative wrapper around clang-format for use within Sublime Text 3. Whilst LLVM does provide a very simple plugin to work with Sublime Text already: https://llvm.org/svn/llvm-project/cfe/trunk/tools/clang-format/clang-format-sublime.py, it doesn't really exploit any of the Sublime Text package functionality. We add new features such as customising the style from a settings file, selecting styles using the Command Palette, and easier installation.
- Install this package through Package Control in the usual way.
- Get the clang-format binary for your platform. All binaries provided below are from the LLVM 3.6 release. They are for 64-bit platforms only:
If you prefer, you can download the entire LLVM toolchain
and extract the
clang-format binary yourself. Just extract the
file and copy
bin/clang-format into your PATH (e.g.
- Set the path to the clang-format binaries. You can do this from within Sublime
Text by choosing
Clang Format - Set Path from the command palette. Hint:
the path should look something like this
If clang-format is in your system path, you shouldn't need to do anything.
- Default shortcut is
super+option+aon OSX and
ctrl+option+aotherwise. This will apply clang-format to the selection.
- From the command palette, you can select the formatting type by using
Clang Format: Select Style. You will find the small number of defaults, and also a new 'Custom' entry. Selecting this entry allows you to customise the style through a settings file. You can access it from the main menu, under
Package Settings. In this file you can add custom rules, such as
Allmenstyle braces, and different indents. For examples see http://clang.llvm.org/docs/ClangFormatStyleOptions.html.
- Settings for the 'Custom' format and others are available through the Sublime Text preferences.
- It is possible to enable the formatter on every save to a C/C++ file. To change settings on a per-package basis, check out the package “Project-Specific”.
If You Liked This
… And want to contribute, PR's gladly accepted!
Maybe you'll like my other plugin, iOpener. It lets you open files by path, with completion, history, and other goodies.
Otherwise, why not pop on over and star this repo on GitHub?
Thanks to the LLVM project for doing the hard work, including writing clang format, and also the original Sublime Text plugin on which this package is based.
Why not go and watch the video that got me interested in clang-format in the first place?