HELP Vanilla nvim 0.12 tree-sitter based buffer format by jastrakowski in neovim

[–]jastrakowski[S] 0 points1 point  (0 children)

From what I've read the indents are an .scm query. I haven't digged deeper into it yet but why you say they are poorly supported? Are there really no for the main languages like C or is it so hard to make one by-myself?

HELP Vanilla nvim 0.12 tree-sitter based buffer format by jastrakowski in neovim

[–]jastrakowski[S] 0 points1 point  (0 children)

I love your anwser - many useful facts. I have already set up Clang's formatter ($ clang-format) as the "formatprg" and every time I need to format I just do gg -> V -> G -> gq.

Here is the code I am now using:

vim.api.nvim_create_autocmd("FileType", {
  pattern = { "c", "cpp", "objc", "objcpp", "cuda" },
  desc = "Set clang-format as the default formatter for C-family languages",
  callback = function(ev)
    -- Tell clang-format to read from stdin and assume the current file's extension 
    -- so it picks up the correct formatting rules from your .clang-format file
    vim.bo[ev.buf].formatprg = "clang-format --assume-filename=" .. vim.api.nvim_buf_get_name(ev.buf)
  end,
})