All Projects → pappasam → vim-filetype-formatter

pappasam / vim-filetype-formatter

Licence: MIT license
Format program files in vim using your favorite command line formatter

Programming Languages

Vim Script
2826 projects

Projects that are alternatives of or similar to vim-filetype-formatter

LunarVim
An IDE layer for Neovim with sane defaults. Completely free and community driven.
Stars: ✭ 9,296 (+44166.67%)
Mutual labels:  nvim, formatters
Nvcode
An IDE layer for Neovim with sane defaults. Completely free and community driven.
Stars: ✭ 6,714 (+31871.43%)
Mutual labels:  nvim, formatters
aerial.nvim
Neovim plugin for a code outline window
Stars: ✭ 485 (+2209.52%)
Mutual labels:  nvim
dotvim
My dotvim - work in progress - Beta stages
Stars: ✭ 27 (+28.57%)
Mutual labels:  nvim
nvim-startup.lua
Displays neovim startup time
Stars: ✭ 53 (+152.38%)
Mutual labels:  nvim
stabilize.nvim
Neovim plugin to stabilize window open/close events.
Stars: ✭ 295 (+1304.76%)
Mutual labels:  nvim
onedark.nvim
One dark and light colorscheme for neovim >= 0.5.0 written in lua based on Atom's One Dark and Light theme. Additionally, it comes with 5 color variant styles
Stars: ✭ 425 (+1923.81%)
Mutual labels:  nvim
duckOS
Yet another hobby x86 UNIX-like operating system written in C and C++. Features a dynamically linked userspace, an in-house c standard library, and more! And yes, it runs DOOM.
Stars: ✭ 250 (+1090.48%)
Mutual labels:  posix
fm-nvim
🗂 Neovim plugin that lets you use your favorite terminal file managers (and fuzzy finders) from within Neovim.
Stars: ✭ 114 (+442.86%)
Mutual labels:  nvim
org-bullets.nvim
No description or website provided.
Stars: ✭ 58 (+176.19%)
Mutual labels:  nvim
virtual-types.nvim
Neovim plugin that shows type annotations as virtual text
Stars: ✭ 171 (+714.29%)
Mutual labels:  nvim
dotfiles
Configuration files for my setup
Stars: ✭ 24 (+14.29%)
Mutual labels:  nvim
pycln
A formatter for finding and removing unused import statements.
Stars: ✭ 161 (+666.67%)
Mutual labels:  formatters
crates.nvim
A neovim plugin that helps managing crates.io dependencies
Stars: ✭ 252 (+1100%)
Mutual labels:  nvim
Dotfiles
KDE Plasma for twm users.
Stars: ✭ 83 (+295.24%)
Mutual labels:  nvim
cervit
Minimal, multi-threaded POSIX HTTP 1.1 server written in C using only system libraries.
Stars: ✭ 19 (-9.52%)
Mutual labels:  posix
FP
Simple FontPreview Shell Script
Stars: ✭ 17 (-19.05%)
Mutual labels:  posix
beeos
A simple "Unix-like" kernel trying to be POSIX compliant
Stars: ✭ 103 (+390.48%)
Mutual labels:  posix
dotfiles
My dotfiles for Neovim, Kitty terminal, Zsh, and a few other things.
Stars: ✭ 101 (+380.95%)
Mutual labels:  nvim
dotfiles
⚫📁 Dotfiles
Stars: ✭ 23 (+9.52%)
Mutual labels:  nvim

Vim-Filetype-Formatter

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

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

Each Vim filetype maps to one command-line command command. This plugin supports any code formatter command 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)
  • Easy debugging of user configuration (:DebugFiletypeFormat)
  • 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

See gif for simple Python example, demonstrating :FiletypeFormat, :LogFiletypeFormat, and :DebugFiletypeFormat:

interactive-demo

Although black works out of the box for Python, the above example overrides the default and combines black with isort and docformatter using unix pipes. This specific example can be achieved with the following configuration in your vimrc / init.vim:

let g:vim_filetype_formatter_commands = {
      \ 'python': 'black -q - | isort -q - | docformatter -',
      \ }

Installation

If using vim-plug, place the following line in the Plugin section of your inti.vim / vimrc:

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

Then run the Ex command:

:PlugInstall

I personally use vim-packager, so if you'd like to go down the "package" rabbit hole, I suggest giving that a try.

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 <silent> <leader>f :FiletypeFormat<cr>
vnoremap <silent> <leader>f :FiletypeFormat<cr>

Default configurations

Default configurations may be overridden by creating our own g:vim_filetype_formatter_commands dictionary. If you would like to map one filetype to another, see g:vim_filetype_formatter_ft_maps. See here for specifics on how to do this.

Non-standard code formatters

In the rare case where a required code formatter does not read from standard input and/or write to standard output, don't panic. With some effort, you can probably still create a working command by chaining the code formatter with standard Unix programs. See the following example, using nginxbeautifier:

\ 'nginx':
\   'dd status=none of=/tmp/nginx.conf >& /dev/null && '
\   . 'nginxbeautifier --space 4 /tmp/nginx.conf >& /dev/null && '
\   . 'cat /tmp/nginx.conf && '
\   . 'rm /tmp/nginx.conf',
  1. dd: read vim-filetype-formatter's standard output as standard input, writing to a temporary file named /tmp/nginx.conf
  2. nginxbeautifier: read from the temporary file and modify that file in-place
  3. cat: write the contents of the temporary file to stdout
  4. rm: remove the temporary file to keep things tidy

It's not exactly pretty, but:

  1. Reality isn't always pretty
  2. We can use the command because it reads from standard input and writes to standard output

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 [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].