Giter Site home page Giter Site logo

formatter.nvim's Introduction

Formatter.nvim

WIP

A format runner for neovim, written in lua.

Install

Using your package manager of choice

" vim-plug
Plug 'mhartington/formatter.nvim'

" dein.nvim
call dein#add('mhartington/formatter.nvim')


" configure the plugin

lua require('formatter').setup(...)
" Provided by setup function
nnoremap <silent> <leader>f :Format<CR>

Configure

By default there are no tools configured. This may change. To config a tool, you can create a table for the filetype and tool you want to use

If you would like to see a list of some common formatters and how to configure them, checkout ./CONFIG.md.

Each format tool config is a function that returns a table. Since each entry is a function, the tables for each file type act as an ordered list (or array). This mean things will run in the order you list them, keep this in mind.

Each formatter should return a table that consist of:

  • exe: the program you wish to run
  • args: a table of args to pass
  • stdin: If it should use stdin or not.
  • cwd : The path to run the program from.
  • ignore_exitcode : Set to true if the program expects non-zero success exit code (optional)
  • tempfile_dir: directory for temp file when not using stdin (optional)
  • tempfile_prefix: prefix for temp file when not using stdin (optional)
  • tempfile_postfix: postfix for temp file when not using stdin (optional)

cwd

The cwd argument can be used for e.g. monolithic projects which contain sources with different styles. Setting cwd to the path of the file being formatted will cause e.g. clang-format to search for the nearest .clang-format file in the file's parent directories.

Format on save

To enable format on save, you can create a autocmd to trigger the formater using FormatWrite, which will format and write to the current saved file.

vim.api.nvim_exec([[
augroup FormatAutogroup
  autocmd!
  autocmd BufWritePost *.js,*.rs,*.lua FormatWrite
augroup END
]], true)

formatter.nvim's People

Contributors

22mahmoud avatar ahmedelgabri avatar akarl avatar bsgalvan avatar horta avatar jameswalmsley avatar lucastrvsn avatar lukas-reineke avatar mhartington avatar mtrajano avatar nsr888 avatar pierremacherel avatar rnprest avatar rohitbishnoi avatar sandersantema avatar shatur avatar williamboman avatar winston0410 avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.