*clang-format.txt*                 Format C, C++, Objective-C using clang-format

Author : rhysd <lin90162@yahoo.co.jp>

CONTENTS         *vim-clang-format-contents*

Introduction     |vim-clang-format-introduction|
Usage            |vim-clang-format-usage|
Install          |vim-clang-format-install|
Dependency       |vim-clang-format-dependency|
Commands         |vim-clang-format-commands|
Mappings         |vim-clang-format-mappings|
Functions        |vim-clang-format-functions|
Variables        |vim-clang-format-variables|
Setup Example    |vim-clang-format-setup-example|
Repository Page  |vim-clang-format-repository-page|
License          |vim-clang-format-license|

==============================================================================
INTRODUCTION                                     *vim-clang-format-introduction*

*vim-clang-format* formats your C, C++ and Objective-C code with specific coding
style using clang.  Following filetypes are supported.

* c
* cpp
* objc
* javascript
* java
* typescript
* proto
* arduino

Screenshot:
http://gifzo.net/BIteGJ9Vasg.gif



==============================================================================
USAGE                                                   *vim-clang-format-usage*

|:ClangFormat| command is available.  If you use it in normal mode, the whole
code will be formatted.  If you use it in visual mode, the selected code will
be formatted.  It is more convenient to map |:ClangFormat| to your favorite key
mapping in normal mode and visual mode.
|'shiftwidth'| and |'expandtab'| are used for formatting.

In addition, |<Plug>(operator-clang-format)| is an operator mapping to format
the |text-objects|.  It is also very useful for expert users.



==============================================================================
DEPENDENCY                                         *vim-clang-format-dependency*

|clang-format| (3.4 or later is required)
    http://clang.llvm.org/docs/ClangFormat.html

    Note:
    clang-format 3.4 in Ubuntu 13.04 seems to be old.  Please use LLVM's
    official apt repository.
    http://llvm.org/apt/

|vim-operator-user| (highly recommended)
    https://github.com/kana/vim-operator-user

|vimproc| (recommended in Windows)
    https://github.com/Shougo/vimproc.vim



==============================================================================
INSTALL                                               *vim-clang-format-install*

Using Vim plugin package manager is recommended.  I use |neobundle| and |vundle|
seems the most famous.
If you want to install manually, it is not recommended, copy files and
directories in autoload, doc and plugin directories to your vim config
directory.  Vim config directory is usually $HOME/vimfiles on Windows or
~/.vim in other operating systems.



==============================================================================
COMMANDS                                             *vim-clang-format-commands*

:[range]ClangFormat                                               *:ClangFormat*
        Format a entire current buffer with clang-format.  If [range] is
        given, |:ClangFormat| formats the range.  In visual mode, |:ClangFormat|
        formats the selected region with linewise way.

:[range]ClangFormatEchoFormattedCode             *:ClangFormatEchoFormattedCode*
        Echo version of |:Clangformat|. Instead of editing buffer directly, echo
        the formatted text.



==============================================================================
MAPPINGS                                             *vim-clang-format-mappings*

<Plug>(operator-clang-format)                    *<Plug>(operator-clang-format)*

    Operator mapping to format source code with clang-format.  To use this
    mapping, |operator-user| is required.



==============================================================================
FUNCTIONS                                           *vim-clang-format-functions*

clang_format#replace({start_line}, {last_line})         *clang_format#replace()*

    This is function version of |:ClangFormat|. {start_line} and {last_line}
    are required.

clang_format#format({start_line}, {last_line})           *clang_format#format()*

    This function returns a formatted code as |String|.



==============================================================================
VARIABLES                                           *vim-clang-format-variables*

g:clang_format#command                                  *g:clang_format#command*

    Name of clang-format command.
    The default value is "clang-format".

g:clang_format#code_style                            *g:clang_format#code_style*

    Base coding style for formatting.  Available coding styles are "llvm",
    "google", "chromium" and "mozilla".
    The default value is "google".

g:clang_format#style_options                      *g:clang_format#style_options*

    Coding style options to specify the rule of format in more detail.  For
    example, using {} in short if statement or not, use C++11 feature or not,
    access modifier offset and so on.  This value is a |Dictionary| whose key
    and value are |String| or |Number|.
    The key and the value are options passed to clang-format's -stryle option.
    You can look up them by executing `clang-format -dump-config` command.  If
    you want to know all of the keys and values, clang-format's documentation
    and API documentation is useful.  In paticular, the following link is
    useful to know.

    CLANG-FORMAT STYLE OPTIONS
    http://clang.llvm.org/docs/ClangFormatStyleOptions.html

g:clang_format#filetype_style_options
                                         *g:clang_format#filetype_style_options*

    If you want to use language-specific style options, you can use this
    variable.  This variable is a |Dictionary| and its key is |filetype|.  You
    can specify the filetype specific style options as a value of the key.
    The format to specify options is the same as |g:clang_format#style_options|.

    For example, if you want to set "C++11" to "Standard", you can specify it
    only when the filetype is "cpp" as below:
>
    " Your common style options
    let g:clang_format#style_options = {
            \ 'AllowShortIfStatementsOnASingleLine' : 'true',
            \ }

    " Your filetype specific options
    let g:clang_format#filetype_style_options = {
                \   'cpp' : {"Standard" : "C++11"},
                \ }
<
g:clang_format#extra_args                            *g:clang_format#extra_args*

    Extra arguments for clang-format.  This |String| value is passed to
    clang-format directly.

g:clang_format#detect_style_file              *g:clang_format#detect_style_file*

    When the value is 1, |vim-clang-format| automatically detects the style file
    like .clang-format or _clang-format and applies the style to formatting.
    The default value is 1.

g:clang_format#auto_format                          *g:clang_format#auto_format*

    When the value is 1, |vim-clang-format| automatically formats a current
    buffer on saving the buffer.  Formatting is executed at |BufWritePre| event.
    The default value is 0.

g:clang_format#auto_format_on_insert_leave
                                    *g:clang_format#auto_format_on_insert_leave*

    When the value is 1, the inserted lines are automatically formatted on
    leaving insert mode.  Formatting is executed on |InsertLeave| event.

g:clang_format#auto_formatexpr		        *g:clang_format#auto_formatexpr*

    When the value is 1, 'formatexpr' option is set automatically in |c|, |cpp|
    and |objc| codes.  Vim's format mappings (e.g. |gq|) get to use |clang-format|
    to format. This option is not comptabile with Vim's `textwidth` feature. You
    must set `textwidth` to `0` when the `formatexpr` is set.

g:clang_format#enable_fallback_style	  *g:clang_format#enable_fallback_style*

    When the value is 0, "-fallback-style=none" option is added on executing
    clang-format command. It means that vim-clang-format does nothing when
    ".clang-format" is not found.
    The default value is 1.



==============================================================================
SETUP EXAMPLE                                   *vim-clang-format-setup-example*

Below is an example for .vimrc.
>
  " your favorite style options
  let g:clang_format#style_options = {
              \ "AccessModifierOffset" : -4,
              \ "AllowShortIfStatementsOnASingleLine" : "true",
              \ "AlwaysBreakTemplateDeclarations" : "true",
              \ "Standard" : "C++11"}

  augroup ClangFormatSettings
    autocmd!
    " map to <Leader>cf in C++ code
    autocmd FileType c,cpp,objc nnoremap <buffer><Leader>cf :<C-u>ClangFormat<CR>
    autocmd FileType c,cpp,objc vnoremap <buffer><Leader>cf :ClangFormat<CR>
    " if you install vim-operator-user
    autocmd FileType c,cpp,objc map <buffer><Leader>x <Plug>(operator-clang-format)
  augroup END
<


==============================================================================
REPOSITORY PAGE                               *vim-clang-format-repository-page*

The latest version of |vim-clang-format| is available at
https://github.com/rhysd/vim-clang-format

Contributions (pull requests) are welcome. None of them is too short.
Especially, English check is very helpful because I'm poor at English :(



==============================================================================
LICENSE                                               *vim-clang-format-license*

|vim-clang-format| is distributed under MIT license.

  Copyright (c) 2013-2017 rhysd

  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files (the
  "Software"), to deal in the Software without restriction, including
  without limitation the rights to use, copy, modify, merge, publish,
  distribute, sublicense, and/or sell copies of the Software, and to
  permit persons to whom the Software is furnished to do so, subject to
  the following conditions:
  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



==============================================================================
vim:tw=78:colorcolumn=78:ts=8:ft=help:norl:noet:fen:fdl=0:
