format.nvim is an asynchronous code formatting plugin for neovim.
With nvim-plug
require('plug').add({
{
'wsdjeg/format.nvim',
cmds = { 'Format' },
},
})
require('format').setup({
custom_formatters = {
lua = {
exe = 'stylua',
args = { '-' },
stdin = true,
},
},
})
:Format
: format current buffer
format code block in markdown:
require('plug').add({
{
'wsdjeg/format.nvim',
config = function()
require('format').setup({
custom_formatters = {
lua = {
exe = 'stylua',
args = { '-' },
stdin = true,
},
},
})
end,
config_before = function()
vim.keymap.set('n', '<leader>bf', '<cmd>Format<cr>', { silent = true })
vim.keymap.set('n', '<leader>lf', function()
local cf = vim.call('context_filetype#get')
if vim.o.filetype == 'markdown' and cf.filetype ~= 'markdown' then
local line1 = cf['range'][1][1]
local line2 = cf['range'][2][1]
vim.cmd(string.format('%s,%sFormat! %s', line1, line2, cf.filetype))
end
end, { silent = true })
end,
cmds = { 'Format' },
depends = { { 'Shougo/context_filetype.vim' } },
},
})
Like this plugin? Star the repository on GitHub.
Love this plugin? Follow me on GitHub and Twitter.
If you encounter any bugs or have suggestions, please file an issue in the issue tracker