Skip to content

kupospelov/nvim-fmt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nvim-fmt

A generic plugin that can be configured to run gofmt, clang-format, or anything else to format the current buffer.

Just call format() to run the formatter or configure the plugin to autoformat the buffer before writing to the file.

Installation

packer.nvim:

require('packer').startup(function(use)
    use('kupospelov/nvim-fmt')
end)

lazy.nvim:

require('lazy').setup({
    { 'kupospelov/nvim-fmt' },
})

Configuration

Settings can be changed using the setup function that accepts a table with the following fields:

  • formatters is a map of formatters keyed by the associated filetypes.
  • options contains optional flags.
    • create_autocmd enables a BufWritePre autocmd that formats the current buffer before writing to the file.

formatter is a shell command that reads from standard input and writes to standard output. In case formatter returns a non-zero exit code, the output is shown as an error message.

Example

local fmt = require('fmt')
fmt.setup({
	formatters = {
		['go'] = 'gofmt',
		['lua'] = 'stylua --search-parent-directories -',
	},
	options = {
		create_autocmd = true,
	},
})

Releases

No releases published

Packages

No packages published

Languages