Clang-format is a tool for 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 here, 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.
clang-format
in one of the following ways:
sudo apt-get install clang-format
or sudo apt-get install clang-format-5.0
.clang-format
binary. Just extract the .tar.xz
file and copy bin/clang-format
into your PATH (e.g. /usr/local/bin
).Clang Format - Set Path
from the command palette. Hint:
the path should look something like this [path/to/clang]/clang/bin/clang-format
.
If clang-format is in your system path, you shouldn't need to do anything.super+option+a
on OSX and option+cmd+a
otherwise.
This will apply clang-format to the selection.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 Allmen
style braces, and different indents. For examples see
http://clang.llvm.org/docs/ClangFormatStyleOptions.html."format_on_save": true
.ctrl+e
for windows and linux
or super+e
for OSX. You can always change the keybinding in the
keymap to your liking.ClangFormat
key,
example project.sublime-settings:{
"folders": [],
"settings": {
"ClangFormat": {
"format_on_save": true
}
}
}
... 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.
Also thanks to y0ssar1an, Bendtherules and other contributors for their improvements!
Why not go and watch the video that got me interested in clang-format in the first place?