Home

Awesome

<div align="center"> <h1> fmt.vim </h1>

Generic code formatting interface for Vim

</div>

Installation

Install aonemd/fmt.vim using a plugin manger such as: vim-plug, NeoBundle, Vundle, or Pathogen.

Usage

The plugin provides the command: Fmt that delegates the auto-formatting to a formatter. Currently, these formatters are used:

LanguageFormatterCommand used
Rustrustfmtrustfmt
Gogofmtgofmt -w
Cclang-formatclang-format -i -style=google
C++clang-formatclang-format -i -style=google
JavaScriptprettierprettier --write
TypeScriptprettierprettier --write
Rubyruforufo

User-defined commands can be used through the global variable g:fmt_commands which overwrites the default commands above. g:fmt_commands example:

let g:fmt_commands = {
      \ 'rust': 'rustfmt',
      \ 'go': 'gofmt -w',
      \ 'c': 'clang-format -i -style=google',
      \ 'cpp': 'clang-format -i -style=google',
      \ 'javascript': 'prettier --write',
      \ 'typescript': 'prettier --write',
      \ 'ruby': 'rufo',
      \ }

In order to use auto-formatting on buffer saving, you can add the following to ~/.vimrc:

autocmd! BufWrite * Fmt

License

See LICENSE.