Settings do not open if json files are assigned to gvim #2507

Closed
opened 2026-01-30 22:56:59 +00:00 by claunia · 19 comments
Owner

Originally created by @maru-sama on GitHub (Jul 3, 2019).

Environment

Windows build number: Version 10.0.18362.207
Windows Terminal version (if applicable): master

Any other software?
gvim

Steps to reproduce

Install gvim
Assign json files to gvim
Try to open the settings in terminal

Expected behavior

Gvim opens the settings file

Actual behavior

Nothing happens

More information:
I have visual studio installed as well. If I change the settings so visual studio is the default handler for json file it works, also notepad. If select gvim from the selection list I can open json files in explorer just fine but trying to open the settings in terminal does not work.
To be honest I am not sure if this is a terminal or vim issue but since terminal is the first application I see this behaviour I filled the bug here.

Originally created by @maru-sama on GitHub (Jul 3, 2019). # Environment ```none Windows build number: Version 10.0.18362.207 Windows Terminal version (if applicable): master Any other software? gvim ``` # Steps to reproduce Install gvim Assign json files to gvim Try to open the settings in terminal # Expected behavior Gvim opens the settings file # Actual behavior Nothing happens More information: I have visual studio installed as well. If I change the settings so visual studio is the default handler for json file it works, also notepad. If select gvim from the selection list I can open json files in explorer just fine but trying to open the settings in terminal does not work. To be honest I am not sure if this is a terminal or vim issue but since terminal is the first application I see this behaviour I filled the bug here.
Author
Owner

@zadjii-msft commented on GitHub (Jul 3, 2019):

That's certainly super curious. I'm pretty sure @DHowett-MSFT uses gvim as his daily driver without issues.

Are you sure the gvim window isn't just opening up somewhere lower in the Z-order?

@zadjii-msft commented on GitHub (Jul 3, 2019): That's certainly super curious. I'm pretty sure @DHowett-MSFT uses gvim as his daily driver without issues. Are you sure the gvim window isn't just opening up somewhere lower in the Z-order?
Author
Owner

@maru-sama commented on GitHub (Jul 3, 2019):

No, nothing happens, as soon as I change this to notepd or visual studio it works right away. I am wondering if setting the standard viewer via explorer -> open with -> set as default is enough or if an entry is missing for gvim in the registry itself.

@maru-sama commented on GitHub (Jul 3, 2019): No, nothing happens, as soon as I change this to notepd or visual studio it works right away. I am wondering if setting the standard viewer via explorer -> open with -> set as default is enough or if an entry is missing for gvim in the registry itself.
Author
Owner

@maru-sama commented on GitHub (Jul 3, 2019):

Since ShellExecute is being used it should "just-work"..

@maru-sama commented on GitHub (Jul 3, 2019): Since ShellExecute is being used it should "just-work"..
Author
Owner

@maru-sama commented on GitHub (Jul 3, 2019):

Ok, I made some progress. It DOES work with gvim if you change the code in LaunchSettings() to

' ShellExecute(nullptr, L"edit", settingsPath.c_str(), nullptr, nullptr, SW_SHOW);

instead of L"open".
That said if I change it this way Visual Studio no longer works. I wonder why gvim is not honoring the "open"

@maru-sama commented on GitHub (Jul 3, 2019): Ok, I made some progress. It DOES work with gvim if you change the code in LaunchSettings() to ' ShellExecute(nullptr, L"**edit**", settingsPath.c_str(), nullptr, nullptr, SW_SHOW); instead of L"**open**". That said if I change it this way Visual Studio no longer works. I wonder why gvim is not honoring the "open"
Author
Owner

@maru-sama commented on GitHub (Jul 3, 2019):

Ok, so I found the entries in the registry for gvim. Apparently
registry
The command contains the gvim executable. As you can see in the screenshoit I changed "edit" to "open" and now gvim works. Since we do not know how an application is configured, wouldn't it make sense to change the call to

ShellExecute(nullptr, nullptr, settingsPath.c_str(), nullptr, nullptr, SW_SHOW);

since this will take care of both cases?

@maru-sama commented on GitHub (Jul 3, 2019): Ok, so I found the entries in the registry for gvim. Apparently ![registry](https://user-images.githubusercontent.com/152713/60608431-be633d80-9dbf-11e9-8dfb-9afdd7741458.png) The command contains the gvim executable. As you can see in the screenshoit I changed "edit" to "open" and now gvim works. Since we do not know how an application is configured, wouldn't it make sense to change the call to > ShellExecute(nullptr, nullptr, settingsPath.c_str(), nullptr, nullptr, SW_SHOW); since this will take care of both cases?
Author
Owner

@DHowett-MSFT commented on GitHub (Jul 3, 2019):

Interesting! So, calling ShellExecute without specifying the verb will use the "default" verb, whatever that happens to be? That'll probably be a pretty good solution.

@DHowett-MSFT commented on GitHub (Jul 3, 2019): Interesting! So, calling `ShellExecute` without specifying the verb will use the "default" verb, whatever that happens to be? That'll probably be a pretty good solution.
Author
Owner

@killroy1971 commented on GitHub (Jul 3, 2019):

Can confirm, but changing the .json_auto_file shell entry from edit to open did not alter Windows Terminal's Settings behavior. I had to remove the registry keys to unset the json application association.

Now, it doesn't prompt me at all when I try to edit the Terminal settings.

Shame, as I'm primarily a Linux user and getting this right in corporate/disconnected environments would make life quite a bit easier.

@killroy1971 commented on GitHub (Jul 3, 2019): Can confirm, but changing the .json_auto_file shell entry from edit to open did not alter Windows Terminal's Settings behavior. I had to remove the registry keys to unset the json application association. Now, it doesn't prompt me at all when I try to edit the Terminal settings. Shame, as I'm primarily a Linux user and getting this right in corporate/disconnected environments would make life quite a bit easier.
Author
Owner

@maru-sama commented on GitHub (Jul 3, 2019):

Interesting! So, calling ShellExecute without specifying the verb will use the "default" verb, whatever that happens to be? That'll probably be a pretty good solution.

That's right although the value can be something else then "open" or "edit". Maybe it is better to try "open" first and if this fails try with "edit", since these are more or less the values that should be normally used.

@maru-sama commented on GitHub (Jul 3, 2019): > Interesting! So, calling `ShellExecute` without specifying the verb will use the "default" verb, whatever that happens to be? That'll probably be a pretty good solution. That's right although the value can be something else then "open" or "edit". Maybe it is better to try "open" first and if this fails try with "edit", since these are more or less the values that should be normally used.
Author
Owner

@perrybucsdad commented on GitHub (Jul 4, 2019):

I think the problem is, for those of us who are not developers, we don't have anything associated with .json files. The solution is by default to associate .json file to notepad. Advanced users can always pick their favorite text editor. With the install from Microsoft store or Github though, we need it to associate with Notepad since it is on every Win 10 OS.

@perrybucsdad commented on GitHub (Jul 4, 2019): I think the problem is, for those of us who are not developers, we don't have anything associated with .json files. The solution is by default to associate .json file to notepad. Advanced users can always pick their favorite text editor. With the install from Microsoft store or Github though, we need it to associate with Notepad since it is on every Win 10 OS.
Author
Owner

@maru-sama commented on GitHub (Jul 4, 2019):

I think this is very easy to implement. First you try to open it with nullptr so the assigned application (if there is one) will be used. You check the return value. If this shows that nothing was found open the file in notepad or wordpad which always exists in windows.

@maru-sama commented on GitHub (Jul 4, 2019): I think this is very easy to implement. First you try to open it with nullptr so the assigned application (if there is one) will be used. You check the return value. If this shows that nothing was found open the file in notepad or wordpad which always exists in windows.
Author
Owner

@perrybucsdad commented on GitHub (Jul 4, 2019):

The common non-programmer will never understand or think to do that though.

@perrybucsdad commented on GitHub (Jul 4, 2019): The common non-programmer will never understand or think to do that though.
Author
Owner

@maru-sama commented on GitHub (Jul 4, 2019):

What I mean is that the terminal first tries to open the assigned app and if this does not work or no application has been assigned, open the settings with notepad.

HINSTANCE res;
res = ShellExecute(nullptr, nullptr, settingsPath.c_str(), nullptr, nullptr, SW_SHOW);
if ((INT_PTR)res < 33)
{
ShellExecute(nullptr, nullptr, L"notepad", settingsPath.c_str(), nullptr, SW_SHOW);
}

@DHowett-MSFT what do you think?

Update: actually this should be < 33

@maru-sama commented on GitHub (Jul 4, 2019): What I mean is that the terminal first tries to open the assigned app and if this does not work or no application has been assigned, open the settings with notepad. > HINSTANCE res; > res = ShellExecute(nullptr, nullptr, settingsPath.c_str(), nullptr, nullptr, SW_SHOW); > if ((INT_PTR)res **< 33**) > { > ShellExecute(nullptr, nullptr, L"notepad", settingsPath.c_str(), nullptr, SW_SHOW); > } @DHowett-MSFT what do you think? **Update:** actually this should be **< 33**
Author
Owner

@ghost commented on GitHub (Aug 3, 2019):

:tada:This issue was addressed in #1841, which has now been successfully released as Windows Terminal Preview v0.3.2142.0.🎉

Handy links:

@ghost commented on GitHub (Aug 3, 2019): :tada:This issue was addressed in #1841, which has now been successfully released as `Windows Terminal Preview v0.3.2142.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v0.3.2142.0) * [Store Download](https://www.microsoft.com/store/apps/9n0dx20hk701?cid=storebadge&ocid=badge)
Author
Owner

@jayhill commented on GitHub (Jun 23, 2020):

This still doesn't work for me in 1.0.200517002-release1.0.
This seems super simplistic, but it looks to me like the issue is just that the path contains a space (…\Windows Terminal\…).
gvim opens, but it opens to the file picker view under <root>\Users\<user>\AppData\Local\Microsoft — it cuts off right where the space is.

@jayhill commented on GitHub (Jun 23, 2020): This still doesn't work for me in `1.0.200517002-release1.0`. This seems super simplistic, but it looks to me like the issue is just that the path contains a space (`…\Windows Terminal\…`). gvim opens, but it opens to the file picker view under `<root>\Users\<user>\AppData\Local\Microsoft` — it cuts off right where the space is.
Author
Owner

@DHowett commented on GitHub (Jun 23, 2020):

Can you run the following from powershell?

gp hkcu:/software/classes/.json
gp hkcu:/software/classes/.json_auto_file/shell/edit/command
@DHowett commented on GitHub (Jun 23, 2020): Can you run the following from powershell? ``` gp hkcu:/software/classes/.json gp hkcu:/software/classes/.json_auto_file/shell/edit/command ```
Author
Owner

@DHowett commented on GitHub (Jun 23, 2020):

(Just to be clear: I’m helping you figure out what is wrong with your JSON association. Once the request to launch the json file leaves Terminal, it’s out of our control as to how it is passed to the final application that will be handling it.)

@DHowett commented on GitHub (Jun 23, 2020): (Just to be clear: I’m helping you figure out what is wrong with your JSON association. Once the request to launch the json file leaves Terminal, it’s out of our control as to how it is passed to the final application that will be handling it.)
Author
Owner

@jayhill commented on GitHub (Jun 23, 2020):

Thanks @DHowett!
I don't have any .json* entries in that location.
I see gvim.exe associated with .json in other places in the registry, but nowhere with a command setting that could be changed from open to edit (assuming that is where this is heading).

@jayhill commented on GitHub (Jun 23, 2020): Thanks @DHowett! I don't have any `.json*` entries in that location. I see gvim.exe associated with .json in other places in the registry, but nowhere with a command setting that could be changed from `open` to `edit` (assuming that is where this is heading).
Author
Owner

@DHowett commented on GitHub (Jun 24, 2020):

The lack of those keys is somewhat surprising (but not terrifically, because file associations went from simple to "dark magic" in the past six years.) I'm more concerned about the escaping, and the quoting, on any arguments passed to gvim. When I checked on my personal machine, I saw my JSON association target (something like) gvim.exe "%1" -- the quotes being, of course, crucial for preserving spaces in paths.

@DHowett commented on GitHub (Jun 24, 2020): The lack of those keys is _somewhat_ surprising (but not terrifically, because file associations went from simple to "dark magic" in the past six years.) I'm more concerned about the escaping, and the quoting, on any arguments passed to gvim. When I checked on my personal machine, I saw my JSON association target (something like) `gvim.exe "%1"` -- the quotes being, of course, crucial for preserving spaces in paths.
Author
Owner

@jayhill commented on GitHub (Jun 24, 2020):

Thanks again. Adding the keys did the trick.
For anyone finding this via search the way I did, this is what I added (update the gvim.exe path based on your installation). YMMV.

[HKEY_CURRENT_USER\SOFTWARE\Classes\.json]
@=".json_auto_file"

[HKEY_CURRENT_USER\SOFTWARE\Classes\.json_auto_file]

[HKEY_CURRENT_USER\SOFTWARE\Classes\.json_auto_file\shell]

[HKEY_CURRENT_USER\SOFTWARE\Classes\.json_auto_file\shell\open]

[HKEY_CURRENT_USER\SOFTWARE\Classes\.json_auto_file\shell\open\command]
@="\"C:\\Users\\JDoe\\scoop\\apps\\vim\\current\\gvim.exe\" \"%1\""

(If adding these directly through the regedit UI, you don't have to escape the path separators or quotation marks like that.)

@jayhill commented on GitHub (Jun 24, 2020): Thanks again. Adding the keys did the trick. For anyone finding this via search the way I did, this is what I added (update the `gvim.exe` path based on your installation). YMMV. ``` [HKEY_CURRENT_USER\SOFTWARE\Classes\.json] @=".json_auto_file" [HKEY_CURRENT_USER\SOFTWARE\Classes\.json_auto_file] [HKEY_CURRENT_USER\SOFTWARE\Classes\.json_auto_file\shell] [HKEY_CURRENT_USER\SOFTWARE\Classes\.json_auto_file\shell\open] [HKEY_CURRENT_USER\SOFTWARE\Classes\.json_auto_file\shell\open\command] @="\"C:\\Users\\JDoe\\scoop\\apps\\vim\\current\\gvim.exe\" \"%1\"" ``` (If adding these directly through the regedit UI, you don't have to escape the path separators or quotation marks like that.)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#2507