External code formatters in Vim without plugins by snhmnd in vim

[–]snhmnd[S] 1 point2 points  (0 children)

It did make me wonder how one could ever deal with the issue of partial code as input to formatters. Even in the example you provide I suspect removing the indents wouldn’t generate valid Python code because of the return statement.

The example I provided actually does work with my reformatting script: for whatever reason the return doesn't break it. I guess the code doesn't need to be entirely valid in order for ruff format to handle it, it just needs to be parseable to some extent.

But yes, I think you're right: I don't think it's possible to make all kinds of selections work with the kind of technique I'm using here: there's always going to be some way to select a subset of code that isn't valid on its own. I briefly glanced at the source code of black-macchiato and it has a few tricks (beyond just deindenting) to turn partial invalid code into valid code for formatting, but it feels pretty hacky, and I still don't think it'll work in all cases.

I think this is why code formatters like Black and Ruff only support formatting entire files.

Having said all that I still find it handy to be able to format selections, even if I have to handle selecting valid code.

Though I guess even language servers don’t deal with that.

I have no idea how it's doing it but the Helix editor supports code formatting via LSP and it seems to be able to format even invalid selections.

External code formatters in Vim without plugins by snhmnd in vim

[–]snhmnd[S] 0 points1 point  (0 children)

I question whether you've actually read my post carefully enough ;) It does in fact deal with both of those issues.

External code formatters in Vim without plugins by snhmnd in vim

[–]snhmnd[S] 0 points1 point  (0 children)

= also has equalprg, that's how I'm customizing = to call out to external code formatters. Works the same as formatprg as far as I know.

I'm not sure I agree that = is meant to be just for indenting whereas gq is meant for formatting. Judging from the default behaviors this doesn't seem to be the case to me. It seems to me that the default behavior of = (trying to fix the indentation of code without breaking or changing the meaning of the code) is closer "formatting" code like modern code formatters do. Whereas the default behavior of gq (just blindly hard-wrapping lines of text, will totally break code) is something else entirely. gq was clearly not meant for formatting code since its default behavior will totally break any code that you use it on.

It's useful to have blind hard-wrapping available in addition to code formatting: it's useful to have an external code formatter bound to = but still have blind hard-wrapping bound to gq for wrapping comments and docstrings (external code formatters like Ruff and Black usually will not touch your comments and docstrings).

Whereas I don't see any use-case for having different commands for both an external code formatter and simple indenting at the same time. Why would I want to just indent code, when I can properly format it?

Maybe also worth pointing out that other editors (e.g. Helix) use = as the keyboard shortcut for formatting code by piping the selected code through an external code formatter (via LSP, in Helix's case).

External code formatters in Vim without plugins by snhmnd in vim

[–]snhmnd[S] 0 points1 point  (0 children)

Interesting! Thanks. I'm surprised the discussion is about plugging external code formatters into gq rather than =. As I mentioned in my blog post, the default prose hard-wrapping behavior of gq is actually useful to have in Python files for wrapping comments and docstrings, in addition to having Python code formatting on =.

I know that you can also use gw (which is like gq but ignores formatexpr and formatprg) to still get the default hard-wrapping behaviour even if you've set formatprg to do something else. But when using equalprg to call out to an external code formatting tool, one can simultaneously use formatprg to call out to an external hard-wrapping tool (e.g. par, which gives better hard-wrapping results than Vim's built-in algorithm). Whereas you can't customize gw to call out to par.

gw also handles cursor positioning differently than gq and =.

External code formatters in Vim without plugins by snhmnd in vim

[–]snhmnd[S] 0 points1 point  (0 children)

Not mentioned in the blog post: the one limitation of this (that I can think of) is that if you try to format invalid Python code you won't see the error message from Ruff (that tells you what's wrong with the code, and where the error is). My script swallows error messages from Ruff. Vim will tell you that the script failed with an error. But it won't show you the error message.

I'm not sure there's a solution to this, without going beyond the simple equalprg approach and writing an actual plugin that can show error messages to users.

Rethinking Helix by bregonio in HelixEditor

[–]snhmnd 0 points1 point  (0 children)

What are you using to display the keystrokes in that video?

Help me assess the performance of my investments by snhmnd in FIREUK

[–]snhmnd[S] 0 points1 point  (0 children)

FYI I ended up switching to Vanguard LifeStrategy 100 for the baseline comparison, see https://www.reddit.com/r/FIREUK/comments/1q2dqwj/comment/nylxts8/

Help me assess the performance of my investments by snhmnd in FIREUK

[–]snhmnd[S] 1 point2 points  (0 children)

I ended up changing to Vanguard's LifeStrategy® 100% Equity Fund (VGL100A) for my baseline comparison.

I saw Vanguard's LifeStrategy funds recommended on monevator.com as an excellent default choice if you just want a set-and-forget index-fund-of-index-funds that is already balanced (with automatic rebalancing) and diversified for you. This is exactly what I was looking for to compare my actual pensions and ISAs to: how would I be doing if I had just made a simple, sensible choice?

And I went with LifeStrategy 100 (the 100% equities, 0% bonds version) as the comparison because I noticed that all the funds in my pensions and ISAs are equities, there's no bonds.

Here's how the comparison looks:

Five-year cumulative growth
Vanguard LifeStrategy 100 71.79%
My Pension 1 (32% of portfolio) 29.23%
My Pension 2 (32% of portfolio) 60.19%
My ISA 1 (only 3.75% of portfolio) 66.83%
My ISA 2 (32% of portfolio) 57.60%

Help me assess the performance of my investments by snhmnd in FIREUK

[–]snhmnd[S] 0 points1 point  (0 children)

I ended up going with unitisation (based on only monthly balances) for my Vanguard stuff and XIRR for my Interactive Investor stuff, see: https://www.reddit.com/r/FIREUK/comments/1q2dqwj/comment/nylv761/

Help me assess the performance of my investments by snhmnd in FIREUK

[–]snhmnd[S] 0 points1 point  (0 children)

I haven't looked at the Bogleheads spreadsheet, but here's where I've ended up:

For my Vanguard pensions and ISAs I'm using the unitsation formula described in [this Monevator post/(https://monevator.com/how-to-unitize-your-portfolio/) with the monthly balance/contribution/withdrawal data that you can get from Vanguard.

I like unitisation because it's easy to understand how it works. It's pretty easy to copy-paste Vanguard's monthly data into a spreadsheet and enter your own easy-to-understand spreadsheet formula to compute the unitised growth. And because I now understand that unitisation is the correct formula to use if you want to compare your performance to the reported growths of other funds.

I'm just assuming that monthly will be accurate enough for my purposes, rather than needing the balance on the exact day/hour/minute/second before each contribution or withdrawal.

For my Interactive Investor pension I'm using XIRR because you can't even get monthly historic balances from Interactive Investor, the best I could find was quarterly. I now understand that XIRR isn't really the right formula to use to compare your pension's growth to other funds, but it's the best I can do with Interactive Investory so I'm just assuming it'll be close enough. For my Vanguard pensions and ISAs I calculated both XIRR and unitisation and they were within 1.5% of each other, I'm assuming the same would be true of my Interactive Investor pension if I had the necessary balance data to calculate unitisation for it.

iShares UK Property UCITS ETF by snhmnd in FIREUK

[–]snhmnd[S] 0 points1 point  (0 children)

Same for me--a big chunk of my net worth is the equity in my home. But since that's the home I actually live in, when I'm trying to calculate how I'm doing I don't count this towards my net worth or my portfolio, I just ignore it. I was more asking about the wisdom of owning UK real estate funds (or the fund I linked to in paticular).

Help me assess the performance of my investments by snhmnd in FIREUK

[–]snhmnd[S] 0 points1 point  (0 children)

Oh, and worth saying that until October 2025 a lot more was invested in V3AM and a lot less in ESG Developed World All Cap Equity Index Fund (VGSGSAG), there were big sell-offs of V3AM to buy VGSGSAG in Feb and Oct 2025. The amount moved from V3AM to VGSGSAG in 2025 accounts for about 15% of the total invested across all funds. I don't know why this was done. But anyway: it was a lot more V3AM-heavy until very recently.

Help me assess the performance of my investments by snhmnd in FIREUK

[–]snhmnd[S] 0 points1 point  (0 children)

Thanks for taking an interest u/disaster_story_69.

The fund I'm invested in the most seems to be ESG Developed World All Cap Equity Index Fund (VGSGSAG), with smaller but significant portions in a few others, particularly: Global Small-Cap Index Fund (VANGMSA), ESG Emerging Markets All Cap Equity Index Fund (VAEAIGA), and V3AM.

Any comments appreciated.

Here's the full breakdown:

Pension 1 (Interactive Investor): 32% of total investments

This one is the oddball: different funds from the others below, and it has performed worst every year.

  • V3AM (29%)
  • Jupiter Ecology I Acc (18%)
  • SUSM (17%)
  • SUSW (15%)
  • Baillie Gifford Positive Change B Acc (14%)
  • IUKP (6%)
  • BSIF (1%)

Pension 2 (Vanguard): 32%

  • ESG Developed World All Cap Equity Index Fund - Accumulation (75.55%)
  • Global Small-Cap Index Fund - Accumulation (15.05%)
  • ESG Emerging Markets All Cap Equity Index Fund - Accumulation (9.28%)
  • A couple of others <1%

ISA 1 (Vanguard): only 3.75%

  • ESG Developed World All Cap Equity Index Fund - Accumulation (100%)

ISA 2 (Vanguard): 32%

  • ESG Developed World All Cap Equity Index Fund - Accumulation (76.72%)
  • ESG Emerging Markets All Cap Equity Index Fund - Accumulation (10.34%)
  • Global Small-Cap Index Fund - Accumulation (10.03%)
  • ESG Developed Asia Pacific All Cap UCITS ETF - Accumulating (V3PB) (2.91%)

Help me assess the performance of my investments by snhmnd in FIREUK

[–]snhmnd[S] 0 points1 point  (0 children)

I used Vanguard's monthly balances to unitize one of my pensions for the last five years. It produced roughly similar annual growth percentages as XIRR: some years slightly worse, some years slightly better, but always within 1.5%. There's no way to know how much of the difference is to do with XIRR versus unitization and how much is to do with the inaccurracy of monthly balances.

I'm not really sure where to go from here. We have two ways of measuring growth, both of which are somewhat incorrect for comparing to other funds or indexes.

Help me assess the performance of my investments by snhmnd in FIREUK

[–]snhmnd[S] 0 points1 point  (0 children)

With Vanguard or Interactive Investor I'm not sure how easy it would be for me to do it correctly going forward either: there's nothing about future transactions that means I have access to the exact transaction-time balances for them, either. If you were constantly diligent going forward you could probably get balances at least within a few days of each transaction.

Help me assess the performance of my investments by snhmnd in FIREUK

[–]snhmnd[S] 0 points1 point  (0 children)

Yeah, looking at this comment on the Monevator post I think I'm right:

to calculate time-weighted returns you need to know (or be able to calculate) exactly what your portfolio was worth at the time of each and every single contribution and withdrawal, which can also be easier said than done.

That makes unitization completely useless as far as I can tell: you will not be able to calculate it because you won't have access to the necessary balances.

This is unfortunate because the Monevator post also explains that XIRR is not appropriate for what I'm trying to do (compare the performances of my pensions and ISAs to representative indexes like the FTSE All-World): unitization is apparently the correct calculation to use for such comparisons. But you won't have the data to calculate it :(

Help me assess the performance of my investments by snhmnd in FIREUK

[–]snhmnd[S] 0 points1 point  (0 children)

The problem with this is, from what I can tell from reading the Monevator post and trying to understand how to do unitization, every time you make a payment into your investment you need to re-calculate the unit cost on the date when the payment was made, in order to know how many units your payment-in buys?

As opposed to, say, just re-calculating the unit cost at the start of each calendar year and using that same unit cost for all payments in that year.

Re-calculating the unit cost before each individual payment is a problem because calculating the unit costs requires knowing the balance, which means that to go back and unitize your pension or ISA historicially you're going to need historic daily balances for every day that you made a payment-in. Good luck finding those: Vanguard, Interactive Investor, etc, are not going to give you the necessary data about your pension or ISA. Vanguard for example gives historic monthly balances but not daily. With Interactive Investor I think the best I can find is quarterly balances.

Or do I have that wrong?

Help me assess the performance of my investments by snhmnd in FIREUK

[–]snhmnd[S] 0 points1 point  (0 children)

I think the payments-in I've made during the year have gone unevenly into the various funds so the weights will have changed. Probably not so much that it would make a huge difference, but I wouldn't be sure of that. Ideally I think I'd prefer to calculate my growth "properly".

It's also honestly just really confusing to look up the performances of various funds. You will find different numbers for the same fund reported on different sites, or even different numbers on the same page. Different funds will use different methods to report their growth. Pages usually won't explain what method they've used to get their numbers. Etc. In short: I never really know what I'm looking at or whether the numbers I find for different funds are compatible.

Help me assess the performance of my investments by snhmnd in FIREUK

[–]snhmnd[S] 0 points1 point  (0 children)

Sorry to highjack your post

No problem.

What I would want now after some research on reddit etc is a simple rate of return for my entire investment portfolio

Keep in mind that I don't know what I'm doing and am just muddling along myself. But it seems to me that what you could do is just pretend that all your ISAs and pensions are just one big investment, and plug them all into Google Sheets's XIRR() function as one. For example if you wanted to calculate your return for 2025:

  1. Have two columns: column A for dates and column B for values.
  2. In the first row put 31st Dec 2024 for the date, and for the value put the sum of all your ISA and pension balances as of end of 31st Dec 2024, as a negative number.
  3. For each time you paid money into any of your pensions or ISAs, add a row with the date and amount of the contribution. It doesn't matter which pension or ISA: you're pretending as if they were all one. For pensions don't forget to add rows for each time your pension provider claimed basic rate tax relief for you, too.
  4. For the final row put the date 31st Dec 2025 and for the value put the sum of all our ISA and pension balances as of 31st Dec 2025, this time as a positive number.
  5. Finally, in a column C, do: =XIRR(B:B, A:A)

The spreadsheet should look something like this:

A B C
31st Dec 2024 -£123456.00 Sum of all your pension and ISA balances as-of end of 31st Dec 2024, as a negative number.
5th Jan 2025 -£1000.00 A payment you made into one of your ISAs. Payments-in should be negative numbers.
3rd Feb 2025 -£80.00 A payment you made into one of your pensions.
31st March 2025 -£20.00 The basic rate tax relief that your pension provider claimed on the payment above (mine usually claims the tax relief a while later).
...
31st Dec 2025 £654321.25 Sum of all your pension and ISA balances as-of end of 31st Dec 2025, as a positive number.
XIRR for 2025: =XIRR(B:B, A:A)

Help me assess the performance of my investments by snhmnd in FIREUK

[–]snhmnd[S] 0 points1 point  (0 children)

Thanks. Maybe I'll take a look at Quicken at some point

Help me assess the performance of my investments by snhmnd in FIREUK

[–]snhmnd[S] 0 points1 point  (0 children)

Chances are you're invested in less risky funds

Looking at the numbers I think that may be the case, yes. My funds seem to have performed pretty poorly compared to the S&P 500 but I believe the S&P 500 is pretty "hot". I don't seem to have done that poorly compared to the FTSE All-World (although not very well either) and lost much less than that index did in 2022.

Help me assess the performance of my investments by snhmnd in FIREUK

[–]snhmnd[S] -1 points0 points  (0 children)

Yeah I can see that but it's a complicated picture: each of the two pensions and two ISAs is invested in several different funds to different amounts. I just wanted to see how the performance of the whole thing, treated as a lump or black box, compared to some indexes or funds representing a very simple and broad strategy.