Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to prevent format on save on fugitive:// buffers #659

Open
dsirov opened this issue Feb 20, 2025 · 1 comment
Open

How to prevent format on save on fugitive:// buffers #659

dsirov opened this issue Feb 20, 2025 · 1 comment

Comments

@dsirov
Copy link

dsirov commented Feb 20, 2025

Hi!

Though others may want auto-format on save when editing fugitive buffers (like staged file buffer), i.e.:
fugitive:///home/user/nvim-test/.git//0/test.py,
I'd like to prevent auto-formatting in such cases as I have encountered some cases in which black works while isort doesn't on staged fugitive buffer, leading to discrepancies.

How can I achieve that via config.?

Thanks!

@dsirov
Copy link
Author

dsirov commented Feb 20, 2025

After more digging, it seems that somehow black is somehow miraculously correctly invoked on fugitive buffer, while isort chokes on such a path (as quite expected).

In any case, here is a LazyVim configuration that prevents it:

return {
  "stevearc/conform.nvim",
  optional = true,
  opts = {
    formatters_by_ft = {
      python = function(bufnr)
        local bufname = vim.api.nvim_buf_get_name(bufnr)
        if bufname:match("^fugitive://") then
          return {}
        else
          return { "black", "isort" }
        end
      end,
    },
  },
}

It may be of interest to add this to documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant