26

So I downloaded, installed, and inserted into path the clang formatting plugin. I also tested it and it works for Google (Mozilla, etc.) formatting options out of the box, yet I cannot get it working with my .clang-format file. (I've put my file into the same folder as my source file, changed its encoding into UTF-8, also tried to put it into clang install folder, add file into project, write its contents inside '{key:value}' yet formatting does not happen). So how do you feed formatting file to chrome-format extension?

My file contents:

 { BasedOnStyle: "LLVM",    IndentWidth: 4 }

My file name:nm.clang-format

Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175
myWallJSON
  • 9,110
  • 22
  • 78
  • 149

4 Answers4

19

Go to Tools->Options->LLVM/Clang->ClangFormat and put file in the Style option field.

Then place your style file named .clang-format (this is the full filename, not an extension) either in the source file's directory or one of its parent directories. Windows Explorer won't let you create filenames with leading . so you need to go to the console for this.

ismail
  • 46,010
  • 9
  • 86
  • 95
ComicSansMS
  • 51,484
  • 14
  • 155
  • 166
  • 6
    Since Clang r190413, one can use '_clang-format' as the name of the format config file, which is often more convenient on Windows. – Hans W Sep 25 '13 at 00:36
  • 2
    In Windows Explorer, Alt+D `cmd /c echo. > .clang-format`, or as a two step process, Alt+D type `cmd` first then `echo. > .clang-format` – John Leidegren Nov 11 '14 at 10:13
  • The file method works for me only if the file is named _clang-format (leading underscore). I created a file named .clang-format, but that one has no effect. – Adrian McCarthy Feb 03 '15 at 17:55
  • 6
    Just append a dot at the end of the filename and windows will happily turn that into the desired filename. Just like that:```.clang-format.``` – simonides Aug 29 '16 at 20:44
8

If like me you got confused later on where the .clang-format was living, use procmon to track the file reads of clang-format.exe

MyDeveloperDay
  • 2,485
  • 1
  • 17
  • 20
3

For the record, it seems that if both "Fallback Style" and "Style" are set to "file", no formatting will happen even if the style file is at its correct location. Setting "Fallback Style" to something different than "file" (e.g. "none") helps.

Eph
  • 225
  • 1
  • 5
1

In VS2019 works if the clang-format file is named as .clang-format.

It must be .clang-format, not .clang-format.txt or clang-format.txt.

Zoe
  • 27,060
  • 21
  • 118
  • 148
ECO
  • 359
  • 2
  • 13