Skip to content
This repository has been archived by the owner on Aug 12, 2023. It is now read-only.

How to use null-ls formatter by default #244

Answered by jose-elias-alvarez
siduck asked this question in Q&A
Discussion options

You must be logged in to vote

Assuming buf_set_keymap is just a wrapper for vim.api.nvim_buf_set_keymap, your keybind is working fine on my end with the following minimal configuration (loaded directly in init.lua after setting up plugins):

local lspconfig = require("lspconfig")
local null_ls = require("null-ls")

lspconfig.tsserver.setup({
    on_attach = function(client, bufnr)
        client.resolved_capabilities.document_formatting = false
        vim.api.nvim_buf_set_keymap(bufnr, "n", "<space>fm", "<cmd>lua vim.lsp.buf.formatting()<CR>", {})
    end,
})

null_ls.config({
    debug = true,
    sources = { null_ls.builtins.formatting.prettier },
})
lspconfig["null-ls"].setup({})

On my end, this makes formatting de…

Replies: 4 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by siduck
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@joshpetit
Comment options

Comment options

You must be logged in to vote
2 replies
@Raagh
Comment options

@Pkcarreno
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants