[vim/vim] runtime:rust: use &formatprg to operate on text object instead of commands (PR #16946)

17 views
Skip to first unread message

Enno

unread,
Mar 22, 2025, 8:19:46 AM3/22/25
to vim/vim, Subscribed

Just an example proposition born out of #16807 to use &formatprg when there is a standard formatter as is the case here instead of adding custom command that cannot operate on a text object and are rather unwieldy to use in comparison to gq. One can still fall back to gw if C style formatting is preferred.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/16946

Commit Summary

  • 8cb1b26 use &formatprg to operate on text object instead of commands

File Changes

(3 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946@github.com>

Enno

unread,
Mar 22, 2025, 8:24:43 AM3/22/25
to vim/vim, Subscribed

NB: The repo listed as maintainer has been stale for the last three years


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/c2745245829@github.com>

KonfektKonfekt left a comment (vim/vim#16946)

NB: The repo listed as maintainer has been stale for the last three years


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/c2745245829@github.com>

Enno

unread,
Mar 22, 2025, 9:01:04 AM3/22/25
to vim/vim, Push

@Konfekt pushed 1 commit.

  • 8f453e9 keep custom commands mostly working as is


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/before/8cb1b262d1167b2e7791fc670db3f81b54923853/after/8f453e9654c0f8b93f55500def1ce2902d2c64d4@github.com>

Enno

unread,
Mar 22, 2025, 9:33:40 AM3/22/25
to vim/vim, Push

@Konfekt pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/before/8f453e9654c0f8b93f55500def1ce2902d2c64d4/after/1ac9bc09c6c82aab012a31e1879cdea447ca93d2@github.com>

Christian Brabandt

unread,
Mar 22, 2025, 10:50:56 AM3/22/25
to vim/vim, Subscribed

But why deleting all the existing formatting code? If that is working, why change it?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/c2745306224@github.com>

chrisbrachrisbra left a comment (vim/vim#16946)

But why deleting all the existing formatting code? If that is working, why change it?


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/c2745306224@github.com>

Enno

unread,
Mar 22, 2025, 3:02:28 PM3/22/25
to vim/vim, Push

@Konfekt pushed 2 commits.

  • 3d4d8b1 Revert removal of redundant code
  • 11bbf21 Revert "remove doc tags"

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/before/1ac9bc09c6c82aab012a31e1879cdea447ca93d2/after/11bbf21ed089001c307c3f635cf8abd6f2ebd4f0@github.com>

Enno

unread,
Mar 22, 2025, 3:04:01 PM3/22/25
to vim/vim, Subscribed

I added it back. It seemed rather redundant and less code is easier to maintain, especially unmaintained one.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/c2745412626@github.com>

KonfektKonfekt left a comment (vim/vim#16946)

I added it back. It seemed rather redundant and less code is easier to maintain, especially unmaintained one.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/c2745412626@github.com>

Christian Brabandt

unread,
Mar 23, 2025, 5:36:38 AM3/23/25
to vim/vim, Subscribed

I added it back. It seemed rather redundant and less code is easier to maintain, especially unmaintained one.

True, but

  • nobody complains until now, so why remove something that is working
  • it may cause confusions by users if formatting suddently works differently (even so the old code worked, see previous item)

and given that there are no more changes in this PR, we can declare this fixed/closed/merged :)


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/c2746114202@github.com>

chrisbrachrisbra left a comment (vim/vim#16946)

I added it back. It seemed rather redundant and less code is easier to maintain, especially unmaintained one.

True, but

  • nobody complains until now, so why remove something that is working
  • it may cause confusions by users if formatting suddently works differently (even so the old code worked, see previous item)

and given that there are no more changes in this PR, we can declare this fixed/closed/merged :)


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/c2746114202@github.com>

Christian Brabandt

unread,
Mar 24, 2025, 3:41:24 PM3/24/25
to vim/vim, Subscribed

Closed #16946.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/issue_event/16962041782@github.com>

Enno

unread,
Mar 25, 2025, 4:32:53 AM3/25/25
to vim/vim, Subscribed

Oops, while resolving merge conflicts I accidentally removed the set-up &formatprg


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/c2750474933@github.com>

KonfektKonfekt left a comment (vim/vim#16946)

Oops, while resolving merge conflicts I accidentally removed the set-up &formatprg


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/c2750474933@github.com>

Aaron Jacobs

unread,
Oct 27, 2025, 4:36:39 AM10/27/25
to vim/vim, Subscribed
jacobsa left a comment (vim/vim#16946)

Hi, are you sure this is a wise choice? It doesn't seem like rustfmt actually formats comments correctly—it doesn't wrap them at textwidth, and it also throws away any indentation before the comment leader (//). This pretty much breaks gq for me. Am I alone? What was the reason for changing it?


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/c3450064597@github.com>

Enno

unread,
Oct 27, 2025, 4:50:17 AM10/27/25
to vim/vim, Subscribed
Konfekt left a comment (vim/vim#16946)

This pretty much breaks gq for me. Am I alone? What was the reason for changing it?

You're not alone


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/c3450110620@github.com>

Aaron Jacobs

unread,
Oct 27, 2025, 4:57:54 AM10/27/25
to vim/vim, Subscribed
jacobsa left a comment (vim/vim#16946)

Thanks. I sent a pull request to revert the bad commit. How do I get a maintainer to look at it? I'm new here.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/c3450151834@github.com>

Enno

unread,
Oct 27, 2025, 5:20:55 AM10/27/25
to vim/vim, Subscribed
Konfekt left a comment (vim/vim#16946)

Conclusion was that there's nothing to revert but simply use gw intended to that end while gq is intended to be used with &formatprg.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/c3450243266@github.com>

Enno

unread,
Oct 27, 2025, 5:22:34 AM10/27/25
to vim/vim, Subscribed
Konfekt left a comment (vim/vim#16946)

Mind that you as a user can change a filetype's settings, such as formatprg as well, see :help filetype-plugin


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/c3450250703@github.com>

Maxim Kim

unread,
Oct 27, 2025, 5:24:43 AM10/27/25
to vim/vim, Subscribed
habamax left a comment (vim/vim#16946)

Conclusion was that there's nothing to revert but simply use gw intended to that end while gq is intended to be used with &formatprg.

For that it should work with ranges, and @jacobsa says it doesn't. I don't use rust, so can't check it myself, but for me it is a no go if formatprg doesn't respect the range to be formatted.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/c3450262431@github.com>

Enno

unread,
Oct 27, 2025, 5:31:22 AM10/27/25
to vim/vim, Subscribed
Konfekt left a comment (vim/vim#16946)

I agree, I just did not imagine


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/c3450292783@github.com>

D. Ben Knoble

unread,
Oct 27, 2025, 11:31:38 AM10/27/25
to vim/vim, Subscribed
benknoble left a comment (vim/vim#16946)

FWIW, I set formatprg=rustfmt myself for Rust. Like with {Black and Python} or {Go}, you have to format enough of the code for the formatter to understand it (so typically a full top-level definition). I don't see anything wrong with this, personally.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/c3451907504@github.com>

dkearns

unread,
Oct 27, 2025, 4:04:57 PM10/27/25
to vim/vim, Subscribed
dkearns left a comment (vim/vim#16946)

Yes, I do the same for Modula-3 where the formatter has the same requirement.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/c3453088872@github.com>

Maxim Kim

unread,
Oct 27, 2025, 4:23:50 PM10/27/25
to vim/vim, Subscribed
habamax left a comment (vim/vim#16946)

That is fine for personal setup, I prefer custom buffer local Fmt command for this but gqq is totally ok. However, for vim it should be able to work with stdin and process a range of lines to be set as formatprg.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/c3453156471@github.com>

dkearns

unread,
Oct 27, 2025, 4:50:05 PM10/27/25
to vim/vim, Subscribed
dkearns left a comment (vim/vim#16946)

It does work with stdin and ranges. As @benknoble mentioned, you just have to pass it something sensible to format.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/c3453249765@github.com>

Christian Brabandt

unread,
Oct 27, 2025, 4:58:03 PM10/27/25
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#16946)

It was the second complaint about a broken rustfmt as gq formatter so I am fine with rolling it back


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16946/c3453295677@github.com>

Reply all
Reply to author
Forward
0 new messages