Unfortunately (for me, not for you),
assoc are fairly deprecated, especially on Windows 11 it seems. Other registry entries override any attempts to change the default behavior via the venerable
ftype command. I'm happy to hear that they are still working for you, but be aware that you may need to transition to other techniques in the future.
So, since I can't use
ftype myself, I can't test out this solution, but I'm gong to propose, as a first pass:
ftype txtfile=wsl -e sh -c "vi \"$(wslpath '%1')\""
Hopefully I'm getting the quoting/escaping correct. I tested it with a hardcoded Windows path (with spaces) from within CMD, at least.
wsl instead of
wsl.exe is the replacement command for launching WSL instances (of any distribution) and is much more flexible than the
Starts WSL by executing (
sh instance with the actual commandline (
-c) we need, which ...
wslpath command to translate the Windows-style path that is passed in to the WSL equivalent. For instance, launching
C:\readme.txt this way will allow Vim to open
Note that no profile or rc (startup) scripts are read from your shell when launching this way, so be mindful of that if there are any environment variable definitions you set there (or aliases, etc.) when inside Vim. This could bite you if you shell-out from Vim to bash often. Otherwise, it's probably not an issue. There are tweaks that you can do to the command line if that is an issue, but it does make launch slightly longer.
If, in the future you find that
ftype no longer works for you, see this answer that I provided just two days ago on an alterative. At that point, I'd totally forgotten about
ftype myself until your question reminded me.