google / vim-codefmt

Vim plugin for syntax-aware code formatting
Apache License 2.0
1.11k stars 114 forks source link

Indentation issue with formatting. #153

Closed priyanshu219 closed 4 years ago

priyanshu219 commented 4 years ago

Recently I installed plugins:

Plug 'google/vim-maktaba'
Plug 'google/vim-codefmt'
Plug 'google/vim-glaive'

And activate it using:

call glaive#Install()
autocmd FileType c,cpp,proto,javascript AutoFormatBuffer clang-format

Now during formatting using:w(as it automatically calling :FormatCode clang-format), its format using indentation of 2, but I want to customise it to 4.

Secondly, it format class in a different way, for example: Before formatting:-

class A {
    public:
       int a,b;
}

After formatting:

class A{
public:
  int a, b;
}

So can anyone tell me how to fix? Or Is this inbuilt? Currently, I am using ubuntu 20.04 and want to format C++ code

dbarnett commented 4 years ago

Looks like these are both questions about clang-format style options and not this vim plugin, correct? I believe you're looking for two of the clang-format tool's style options IndentWidth and AccessModifierOffset and you can put those in a .clang-format file in your project, as explained at https://clang.llvm.org/docs/ClangFormatStyleOptions.html.

In general you should try calling clang-format on the command-line and see if it has the same behavior. You can ask about all the specifics of clang-format tool on the mailing lists for LLVM.

panzhongxian commented 4 years ago

I am confusing by the same issue.

I have tried calling from one the command-line. The only difference between calling on the commandline and formatting by vim-codefmt is the single whitespace before public. It disappared when using vim-codefmt.

My ~/.clang-format file content:

BasedOnStyle: Google