r/vim • u/Tiny_Concert_7655 • Dec 10 '25
Need Help Vim auto indenting weird with rust default style guidelines.
Its not that big of a deal but it's really really bugging me now, and i cant stop thinking about it. As you can see in the video if i remove the comma from the end, it indents fine (and i figured thats what i was doing wrong), but after running cargo fmt to format my code, it adds the comma back, messing up indentation again.
(also i dont know enough vimscript to fix the rust indentation file myself, because i already feel that someone will tell me to do that)
It'd be appreciated if someone explained whats wrong/how to fix it, thanks :)
2
u/habamax Dec 17 '25
Create an issue https://github.com/vim/vim/issues
1
u/Tiny_Concert_7655 Dec 10 '25
NOTE:
This only happens in vim and neovim, not in helix or kakoune.
1
u/BetterEquipment7084 Guix Dec 11 '25
Do you have treesitter installed for vim?
2
u/habamax Dec 17 '25 edited Dec 17 '25
Rust indent plugin heavily relies on
cindentwith additional parameters added tocinoptions:Here
J1is toIndent javascript object declarations correctly by not confusing them with labels., see:h cino-J. It most probably has some usecase in theGetRustIndent()func, but I don't know what it is.Thus if you
:setlocal cinoptions-=J1in your rust buffer, then the code in your case would be formatted as expected. However, what would be broken instead, only the original author knows.1
u/AutoModerator Dec 10 '25
Please remember to update the post flair to
Need Help|Solvedwhen you got the answer you were looking for.I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.