https://github.com/umaumax/vim-format
vim plugin for misc files formatting
https://github.com/umaumax/vim-format
formatter plugin vim
Last synced: 8 months ago
JSON representation
vim plugin for misc files formatting
- Host: GitHub
- URL: https://github.com/umaumax/vim-format
- Owner: umaumax
- Created: 2019-06-06T14:28:30.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-08-28T12:40:57.000Z (almost 2 years ago)
- Last Synced: 2025-08-20T06:48:00.670Z (10 months ago)
- Topics: formatter, plugin, vim
- Language: Vim Script
- Homepage:
- Size: 32.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# vim-format
vim plugin for misc formatting
## support format list
* cmake
* json
* python
* yaml
* toml
* sh,zsh
* rust
* nasm
* golang
* awk
* perl
### cmake - cmake_format
[umaumax/cmake\_format: Source code formatter for cmake listfiles\.]( https://github.com/umaumax/cmake_format )
``` bash
pip install https://github.com/umaumax/cmake_format/archive/master.tar.gz
```
### json - prettier, jq
prettier
``` bash
npm install -g prettier
```
jq
[Download jq]( https://stedolan.github.io/jq/download/ )
``` bash
# Mac OS X
brew install jq
# Ubuntu
sudo apt-get install jq
```
### python - autopep8
[hhatto/autopep8: A tool that automatically formats Python code to conform to the PEP 8 style guide\.]( https://github.com/hhatto/autopep8 )
``` bash
pip install autopep8
```
### yaml - prettier / yamlfmt / align-yaml
[gechr/yamlfmt: 📄 YAML file formatter]( https://github.com/gechr/yamlfmt )
``` bash
go get -u github.com/gechr/yamlfmt
```
[align\-yaml]( https://github.com/jonschlinkert/align-yaml )
``` bash
npm install -g align-yaml
```
### toml - prettier
``` bash
cargo install taplo-cli
npm install prettier prettier-plugin-toml --save-dev --save-exact
```
### typescript - prettier
### sh,zsh - shfmt
[mvdan/sh: A shell parser, formatter, and interpreter \(POSIX/Bash/mksh\)]( https://github.com/mvdan/sh )
### rust - rustfmt
``` bash
rustup component add rustfmt
```
`rustfmt`の仕様でファイル名を指定するとそのファイルを基準にして,各モジュールが適切に設定されているかを検査する
一時ファイルを利用してファイルを保存すると,そのときにエラーが発生してしまう
その一時ファイルを編集対象のファイルと同じディレクトリに配置すれば,その検査自体は問題ないが,
フォーマットされた結果が,stdoutに他のファイルの結果を含めて出力されてしまう問題がある
### nasm - nasmfmt
[yamnikov\-oleg/nasmfmt: Formatter for NASM source files]( https://github.com/yamnikov-oleg/nasmfmt )
``` bash
go get -u github.com/yamnikov-oleg/nasmfmt
```
### prettier for json, toml, yaml, typescript, html
``` bash
npm install prettier prettier-plugin-toml --save-dev --save-exact
```
### golang - gofmt
### awk - gawk
### perl - perltidy
``` bash
# mac
brew install perltidy
# ubuntu
sudo apt install -y perltidy
```
### lua - stylua
[JohnnyMorganz/StyLua: An opinionated Lua code formatter]( https://github.com/JohnnyMorganz/StyLua )
``` bash
cargo install stylua
```
### kotlin - ktlint
[pinterest/ktlint: An anti-bikeshedding Kotlin linter with built-in formatter]( https://github.com/pinterest/ktlint )
NOTE: A shell command at `:KtFormat` always return true even if ktlint failed with error.
----
## how to use
``` vim
Plug 'umaumax/vim-format'
let g:my_format_flag=1
" auto setting
let g:vim_format_fmt_on_save = 1
let g:Vim_format_pre_hook = { key, args -> g:my_format_flag }
" example of manual setting for json
let g:vim_format_fmt_on_save = 0
augroup json_group
autocmd!
autocmd FileType json autocmd BufWinEnter *.json command! -bar Format :JsonFormat
autocmd FileType json autocmd BufWritePre *.json if g:my_format_flag | :JsonFormat | endif
autocmd FileType json autocmd! json_group FileType
augroup END
" for original command
let g:vim_format_list={
\ 'jenkins':{'autocmd':['*.groovy'],'cmds':[{'requirements':['goenkins-format'], 'shell':'cat {input_file} | goenkins-format'}]},
\ }
```
The plugin will automatically define the commands with the following rules.
e.g.
* key is python: PythonFormat
* key is awk: AwkFormat