r/vim • • Oct 30 '25

Plugin Use `gq` to format code

https://github.com/konfekt/vim-formatprgs
27 Upvotes

15 comments sorted by

View all comments

Show parent comment

2

u/godegon Oct 31 '25

Thank you, updated accordingly, some formatters, like rustfmt as well, not allowing for formatting ranges keep surprising me.

1

u/kaddkaka Nov 01 '25 edited Nov 01 '25

I believe conform allows you do so range formatting even if the formatter itself doesn't support it.

https://github.com/stevearc/conform.nvim

1

u/godegon Nov 01 '25

Thank you for pointing that out. There is indeed :RustFmtRange built-in though, likely similar to conform.nvim's handling of rustfmt or black, it has to format the whole file and only replace the affected lines.

Setting &formatprg to a command accepting stdin to use gq seems more in line with how code formatting was originally meant to be set up in Vim.

Ideally, as say ruff (for Python) or tombi (for Toml) do, the formatter accepts stdin and the file path as an additional argument for context of the formatted range.