问题
When opening a URL via view_in_browser command it opens
file:///Applications/MAMP/htdocs/file.php
instead I want it to open
http://localhost:8888/file.php
I was able to do it before, but it was set up 5 years ago and the computer is dead.
I don't want to do anything with project URLs or setup sidebar enhancement packages, I also tried creating a custom plugin as in https://forum.sublimetext.com/t/how-to-view-in-browser/3225/7
Which overrides the open_browser command, but it doesn't work.
Is there not an arg I can specify in the key bindings to prepend a URL? Something like
{ "keys": [ "super+e" ],
"command": "view_in_browser"
"args": {"url": "http://localhost:8888/"}
}
May be there's an existing package that does this?
Seems so simple, but is so complicated to do.. I'm on sublime 3
回答1:
Couldn't find any other method apart from sidebar enhancements route so did the following
Installed sidebar enhancements, details here: https://www.hongkiat.com/blog/preview-in-localhost/
Opened the folder "htdocs" then right click folder > Project > Edit preview URLs
And pasted the following:
{
"/Applications/MAMP/htdocs/":{
"url_testing":"http://localhost:8888/"
}
}
/Applications/MAMP/htdocs/ : path to your files
http://localhost:8888/ : is path to local machine URL
Then go to Preference > Keybindings and in the right window paste
{ "keys": ["ctrl+l" ],
"command": "side_bar_open_in_browser" ,
"args":{"paths":[], "type":"testing", "browser":"Chrome"}
}
Now when you press control + l on the computer it will open up the URL with localhost prepended.
Hope this helps!
Personal observation: the granular control of sidebarenhacements is great and all, but this is overly complicated if you simply want to bind a key to open up chrome window with localhost prepended regardless of project, url type, file paths etc. Hope this is changed in the future.
来源:https://stackoverflow.com/questions/59170056/open-up-url-on-local-machine-sublime