ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Clang Format

by rosshemsley ST3

A C++ code formatter based on Clang Format, for beautiful code with minimal effort in Sublime Text 3

Details

Installs

  • Total 18K
  • Win 7K
  • OS X 5K
  • Linux 7K
Mar 26 Mar 25 Mar 24 Mar 23 Mar 22 Mar 21 Mar 20 Mar 19 Mar 18 Mar 17 Mar 16 Mar 15 Mar 14 Mar 13 Mar 12 Mar 11 Mar 10 Mar 9 Mar 8 Mar 7 Mar 6 Mar 5 Mar 4 Mar 3 Mar 2 Mar 1 Feb 28 Feb 27 Feb 26 Feb 25 Feb 24 Feb 23 Feb 22 Feb 21 Feb 20 Feb 19 Feb 18 Feb 17 Feb 16 Feb 15 Feb 14 Feb 13 Feb 12 Feb 11 Feb 10 Feb 9
Windows 0 5 15 17 11 7 19 8 14 11 11 14 15 9 8 8 11 11 10 10 10 6 6 12 14 10 12 12 6 3 12 8 9 13 9 8 9 10 10 12 17 6 10 4 12 9
OS X 0 4 9 5 9 5 8 3 5 7 11 4 18 4 5 9 7 5 13 12 8 2 5 5 14 9 12 4 6 9 10 13 14 14 3 1 7 9 13 9 11 8 3 5 7 15
Linux 0 8 20 18 17 15 15 10 8 11 12 22 14 12 10 4 20 14 19 18 8 11 13 8 15 8 11 14 10 4 15 12 16 15 13 14 11 11 20 11 17 18 10 10 15 10

Readme

Source
raw.​githubusercontent.​com

Clang Format

Package Control

What it does

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.

demo

About

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.

Installing

  • Download the entire LLVM toolchain and extract the clang-format binary. Just extract the .tar.xz file and copy bin/clang-format into your PATH (e.g. /usr/local/bin).
  • Install this package through Package Control in the usual way.
  • 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 [path/to/clang]/clang/bin/clang-format. If clang-format is in your system path, you shouldn't need to do anything.

Use

  • Default shortcut is super+option+a on OSX and ctrl+option+a otherwise. 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 Allmen style 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 run the formatter on every save to a file, change settings to "format_on_save": true.
  • To change settings on a per-package basis, add them under ClangFormat key, example project.sublime-settings:
{
  "folders": [],
  "settings": {
    "ClangFormat": {
      "format_on_save": true
    }
  }
}

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?

Credits

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!

Finally

Why not go and watch the video that got me interested in clang-format in the first place?

The Care and Feeding of C++'s Dragons