simpleclangformat.vim


Ⅰ. 插件描述

Small plugin to use clang-format in Vim and Neovim. Not actively maintained

Ⅱ. 基本信息

创建日期:  2018-07-15
使用用户:  1
Github星:  4
插件作者:  Andrey Orst

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'andreyorst/simpleclangformat-vim'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'andreyorst/simpleclangformat-vim'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'andreyorst/simpleclangformat-vim'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/andreyorst/simpleclangformat.vim

Ⅳ. 文档说明

# Maintenance warning
I'm not using Vim as my primary editor anymore, therefore I'm not writing
Vim Script and not using this plugin. My focus shifted to
Kakoune editor, which I do like more than Vim and its
scripting model is more appealing to me. This plugin works, it is capable to do
many things, but currently I'm not using it and not planning to. Therefore if
Vim will change somehow that this plugin will stop working I will not know about
it and will not be able to fix it. I'll gradually accept pull request that fixes
the problem, but that's it. If you want to take the task of maintenance and
improvement of this plugin, contact me via e-mail or
open an issue I'll provide an ownership for this repository, or add a note about
currently maintained fork.

SimpleClangFormat.vim

Simpler usage of clang-format in Vim and NeoVim.

What this plugin does:

This Plugin adds new command: :ClangFormat. You can specify a style:

  • :ClangFormat llvm
  • :ClangFormat Mozilla
  • :ClangFormat Chrome
  • :ClangFormat Chromium
  • :ClangFormat Webkit
  • :ClangFormat file

Or you can pass options directly:

:ClangFormat {BasedOnStyle: Webkit, IndentWidth: 4}

Furthermore, you can create your own styles.

What this plugin doesn't:

  • Modify you &equalprg settings.
  • Provide collections of custom formatting styles except those, which are shipped with clang-format.
  • Support setting BraceWrapping: custom option in .vimrc (yet).

Install

If you're using vim-plug, add this to your .vimrc or init.vim:

Plug 'andreyorst/SimpleClangFormat.vim'

Then do:

:w | so % | PlugInstall

Configuration

This plugin can be configured in your .vimrc, by using list notation. If no
style specified :ClangFormat will fallback to this configuration. If
no configuration found in .vimrc, default style is used.

Configuration example:

let g:SimpleClangFormat#options = {
    \ "BasedOnStyle": "webkit",
    \ "IndentWidth": 4,
    \ "TabWidth": 4,
    \ "PointerAlignment": "Left",
    \ "AlignAfterOpenBracket": "DontAlign",
    \ "AlignConsecutiveAssignments": "true",
    \ "AlignConsecutiveDeclarations": "true",
    \ "AlignTrailingComments": "true",
    \ "BreakBeforeBraces": "Stroustrup",
    \ "UseTab": "ForIndentation",
    \ "SortIncludes": "false",
\}

Also SimpleClangFormat.vim can track your shiftwidth and tabstop settings
with any of this variables:

let g:SimpleClangFormat#useShiftWidth = 1
let g:SimpleClangFormat#useTabStop = 1`

If one of these variables is specified, :ClangFormat will force all styles to use IndentWidth: 4 or TabWidth: 4 accordingly.
User Styles are immune to these settings, so you need to specify TabWidth and IndentWidth.
If you pass option list directly, using :ClangFormat {...} notation, explicit declaration of any of these settings will ignore user tabstop and shiftwidth settings:

:let g:SimpleClangFormat#useShiftWidth = 1
:let g:SimpleClangFormat#useTabStop = 1`
:set tabstops=8 | set shiftwidthw=8

:ClangFormat {BasedOnStyle: LLVM} " Will be extended with IndentWidth: 8, TabWidth: 8
:ClangFormat {BasedOnStyle: LLVM, IndentWidth: 2, TabWidth: 2} " Will ignore user tabstop and shiftwidth settings

Custom User Styles

You can create custom user styles to use with :ClangFormat. The syntax is similar to the
g:SimpleClangFormat#options, except that you specify lists inside list:

let g:SimpleClangFormat#userStyles = {
    \ "AStyle": {
        \ "BasedOnStyle": "webkit"
        " rest of AStyle settings here
    \},
    \ "Stroustrup": {
        \ "BasedOnStyle": "llvm"
        ...
    \},
}

Custom user styles are not affected by g:SimpleClangFormat#useShiftWidth and g:SimpleClangFormat#useTabStop.

About

This plugin is created and being maintained by @andreyorst.
It is being tested against Vim 8.0, Vim 7.4.1689 and neovim 0.3.*. Other versions
are not officially supported, but might work. If you found an issue, or want to
propose a change, you're welcome to do so at SimpleClangFormat.vim GitHub
repository: https://github.com/andreyorst/SimpleClangFormat.vim

添加新评论