Setting IndentWidth does not work in clang-format

I have .clang-formatin my home directory and set indentwidth 4 as follows.

BasedOnStyle:  LLVM
Standard:        Cpp11
IndentWidth:     4   
TabWidth:        4   
UseTab:          Never 

But when I use clang-format -style='~/.clang-format' a.cppto format my code, the width of the indentation becomes 2. like:

// See this indent width 2. The original file has width 4, 
// but clang-format changes it to width 2.
int main(int argc, char const *argv[]) {
  A a;  
  a.bar();

Output clang-format -version -

LLVM (http://llvm.org/):
  LLVM version 3.4.2
  Optimized build.
  Default target: x86_64-unknown-linux-gnu
  Host CPU: core-avx-i

How to enable clang-format format for my code (.h, .c, ..) with indentation width 4?

+4
source share
1 answer

http://clang.llvm.org/docs/ClangFormat.html

-style . file, .clang-format, stdin.

, :

clang-format -style="{IndentWidth: 4,TabWidth: 4}"

-dump-config, .


-style='~/.clang-format'

~ , , . . -style , .

+9

All Articles