How do you align journal amounts in VS Code?

(See also the original mastodon thread.)

I am looking for a way to get dollar amounts to align to the right in VS Code. The hledger extension doesn't do this, and I haven't found one that does.

hledger-vscode extension doesn't do it

ledger extension doesn't do it

Beancount extension says it can align decimal marks, when you type them, but it didn't for me

Beancount Formatter extension will do it if you set the file's type to beancount and press Shift-Alt-F (or something else on linux). But only if you use beancount-style commodity symbols: capital letters on the right side.

I use Meta-Q in ledger-mode in Emacs to do it (running in a VSCode terminal pane, perhaps).

:LedgerAlign vim-ledger does this.

Maybe you can draw inspiration from there and implement one for VSCode?

Ledger's print seems to align amounts globally, at least to some extent. So for ledger-compatible journals, filtering the transaction or journal through ledger print (manually) might be another way.

Thank you for those suggestions. For now I will work with a vertical ruler in VS Code to make it easier to do manual alignment.

Oh, how does one do that ?

I wrote a little python script that aligns amounts to the right at the specified column.
It also adds missing decimals number.

I use it after running the print command to reorder transactions in chronological order

If you want to check it out it's here (expected directory structure, the script and the Just file): Hledger journal cleanup · GitHub

Obviously, don't test it on your main journal. Test it on a copy.

1 Like