icew4ll / vim-filetype-formatter

Format program files in vim using your favorite command line formatter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vim-Filetype-Formatter

A simple, cross language Vim code formatter plugin supporting both range and full-file formatting. By default, it provides the following filetype formatters:

Don't like the defaults? Writing custom commands is easy!

Each Vim filetype maps to one command-line code-formatting command. This plugin supports any language code formatter as long as it:

  1. Reads from standard input.
  2. Writes to standard output.
  3. Is in your PATH. Vim-filetype-formatter uses code formatters; it does not install them.

Requires:

  • A recent version of Neovim or Vim 8.
  • Bash (/bin/bash)

Differentiating Features

  • Respects configuration files (pyproject.toml, .rustfmt.toml, .prettierrc.toml, etc)
  • Accepts visually-selected ranges for any formatter
  • Preserves Vim cursor location after the formatter has run
  • Clear logging so you can see why a formatter is or isn't working (:LogFiletypeFormat)
  • Chain formatters together with Unix pipes
  • Configurable, with sane defaults
  • Simple, extendable codebase
  • Modular: does not pollute your Vim environment with remappings / poor Vim plugin practices

Installation

Use Vim-Plug. Once you've installed Vim-Plug, place the following line in the Plugin section of your vimrc:

" ~/.vimrc
Plug 'pappasam/vim-filetype-formatter'

Then run the Ex command:

:PlugInstall

Full Documentation

From within Vim, type:

:help filetype_formatter

Key mappings

This plugin provides no default key mappings. I recommend setting a key mapping for normal mode and visual mode like this:

" ~/.vimrc
nnoremap <leader>f :FiletypeFormat<cr>
vnoremap <leader>f :FiletypeFormat<cr>

Default configurations

Default configurations may be overridden by creating our own g:vim_filetype_formatter_commands dictionary. See here for specifics on how to do this.

To see the latest provided defaults / options, please see here.

Notes

This plugin prioritizes simplicity and ease of use on a POSIX-compliant system. Support for Windows and other non-Unix derivatives is out of scope.

Written by

Samuel Roeca samuel.roeca@gmail.com

About

Format program files in vim using your favorite command line formatter

License:MIT License


Languages

Language:Vim Script 100.0%