Open up URL on local machine sublime

末鹿安然 提交于 2021-02-11 13:41:53

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!