/neoformat

:sparkles: A (Neo)vim plugin for formatting code.

Primary LanguageVimLBSD 2-Clause "Simplified" LicenseBSD-2-Clause

Neoformat Build Status

A Neovim plugin for formatting code, with preliminary support for Vim.

Neoformat uses a variety of formatters for differing filetypes. Currently, Neoformat will run a formatter asynchronously, and on success it will update the current buffer with the formatted text. On a formatter failure, Neoformat will try the next formatter defined for the filetype.

The job control is based off vim-go's.

Basic Usage

Format the current file using its filetype

:Neoformat

Or specify a certain formatter (must be defined for the current filetype)

:Neoformat js-beautify

Install

vim-plug

Plug 'sbdchd/neoformat'

Current Limitation(s)

In order to preserve marks, jumps, etc., Neoformat uses Vim's setline() function to insert the formatted text. If the buffer is changed before the formatter has completed, then the updated text will be put into the current buffer.

To prevent this, format jobs are cancelled when changing / closing the buffer.

So don't switch buffers before the the formatting is complete!

Note: This should be resolved when setbufline() is added.

By default, Neoformat reads from the current buffer, not the current file. This can be changed via the configuration variable g:neoformat_read_from_buffer.

With Vim, some of the formatters do not function, e.g. remark.

Config [Optional]

Define custom formatters.

let g:neoformat_python_autopep8 = {
            \ 'exe': 'autopep8'
            \ }

let g:neoformat_enabled_python = ['autopep8']

Configure enabled formatters.

let g:neoformat_enabled_python = ['autopep8', 'yapf']

Enable basic formatting when a filetype is not found. Disabled by default.

" Enable alignment
let g:neoformat_basic_format_align = 1

" Enable tab to spaces conversion
let g:neoformat_basic_format_retab = 1

" Enable trimmming of trailing whitespace
let g:neoformat_basic_format_trim = 1

Make Neoformat read from the file instead of the buffer.

let g:neoformat_read_from_buffer = 0

When debugging, you can enable either of following variables for extra logging.

let g:neoformat_verbose = 1 " only affects the verbosity of Neoformat
" Or
let &verbose            = 1 " also increases verbosity of the editor as a whole

Supported Filetypes