mhartington/formatter.nvim

Using prettier to format typescriptreact files

Closed this issue · 1 comments

Please how to go about this?

this is my format.lua file, maybe it can help you

local prettier = { exe = 'prettier', args = {'--stdin-filepath', vim.api.nvim_buf_get_name(0)}, stdin = true }
local black = { exe = 'black', args = {'-'}, stdin = true }
local gofmt = { exe = 'gofmt', args = {}, stdin = true }
local rustfmt = { exe = 'rustfmt', args = {'--emit=stdout'}, stdin = true }
local clang_format = { exe = 'clang-format', args = {}, stdin = true }
local stylua = { exe = 'stylua', args = {'--indent-width', '2', '-'}, stdin = true }

require('formatter').setup({
    filetype = {
        javascript = { prettier },
        typescript = { prettier },
        python = { black },
        go = { gofmt },
        rust = { rustfmt },
        c = { clang_format },
        lua = { stylua },
        -- Add more filetypes and corresponding formatters as needed
    }
})

-- leader f/F to format/format-write
vim.api.nvim_set_keymap("n", "<leader>f", "<cmd>Format<CR>", { noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "<leader>F", "<cmd>FormatWrite<CR>", { noremap = true, silent = true })