Open up URL on local machine sublime - sublimetext3

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

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.

Related

sublime tab right-click menu to add a save all options

I recently upgraded the version, there is a need to transplant function, but this feature I do not know because it is installed what plug-in? So now need to manually add, I know you can use shortcut keys binding, but my shortcut keys are occupied, and if you continue to set up but it is not convenient to use.
{ "keys": ["ctrl+*+*"], "command": "save_all" }
demo
needs improvement
Find the Default.sublime-package file,
rename Default.sublime-package to a zip file and unzip.
There we find the file Tab Context.sublime-menu and Context.sublime-menu
Add {"command": "save_all", "caption": "Save All"},
The effect is as follows:
Tab Context
Context

Plugin for Indentation in Sublime Text 3 [duplicate]

I've got some poorly-formatted HTML code that I'd like to reformat. Is there a command that will automatically reformat HTML code in Sublime Text 2 so it looks better and is easier to read?
You don't need any plugins to do this.
Just select all lines (CTRL+A) and then from the menu select Edit → Line → Reindent.
This will work if your file is saved with an extension that contains HTML like .html or .php.
If you do this often, you may find this key mapping useful:
{ "keys": ["ctrl+shift+r"], "command": "reindent" , "args": { "single_line": false } }
If your file is not saved (e.g. you just pasted in a snippet to a new window), you can manually set the language for indentation by selecting the menu View → Syntax → language of choice before selecting the reindent option.
There are half a dozen or so ways to format HTML in Sublime. I've tested each of the most popular plugins (see the writeup I did on my blog for full details), but here's a quick overview of some of the most popular options:
Reindent command
Pros:
Ships with Sublime, so no plugin install needed
Cons:
Doesn't delete extra blank lines
Can't handle minified HTML, lines with multiple open tags
Doesn't properly format <script> blocks
Tag
Pros:
Supports ST2/ST3
Removes extra blank lines
No binary dependencies
Cons:
Chokes on PHP tags
Doesn't handle <script> blocks correctly
HTMLTidy
Pros:
Handles PHP tags
Some settings to tweak formatting
Cons:
Requires PHP (falls back to web service)
ST2 only
Abandoned?
HTMLBeautify
Pros:
Supports ST2/ST3
Simple and no binaray dependencies
Support for OS X, Win and Linux
Cons:
Chokes a bit with inline comments
Does not expand minimized or compressed code
HTML-CSS-JS Prettify
Pros:
Supports ST2/ST3
Handles HTML, CSS, JS
Great integration with Sublime's menus
Highly customizable
Per-project settings
Format on save option
Cons:
Requires Node.js
Not great for embedded PHP
Which is best?
HTML-CSS-JS Prettify is the winner in my book. Lots of great features, not much to complain about.
The only package I've been able to find is Tag.
You can install it using the package control. https://sublime.wbond.net
After installing package control. Go to package control (Preferences -> Package Control) then type install, hit enter. Then type tag and hit enter.
After installing Tag, highlight the text and press the shortcut Ctrl+Alt+F.
I recommend this plugin: HTML/CSS/JS Prettify, It really works.
After the installation, just select the code and press CTRL+SHIFT+H.
Done!
Just a general tip. What I did to auto-tidy up my HTML, was install the package HTML_Tidy, and then add the following keybinding to the default settings (which I use):
{ "keys": ["enter"], "command": "html_tidy" },
this runs HTML Tidy with every enter. There may be drawbacks to this, I'm quite new to Sublime myself, but it seems to do what I want :)
Altough the question is for HTML, I would also additionally like to give info about how to auto-format your Javascript code for Sublime Text 2;
You can select all your code(CTRL+A) and use the in-app functionality, reindent(Edit -> Line -> Reindent) or you can use JsFormat formatting plugin for Sublime Text 2 if you would like to have more customizable settings on how to format your code to addition to the Sublime Text's default tab/indent settings.
https://github.com/jdc0589/JsFormat
You can easily install JsFormat with using Package Control (Preferences -> Package Control) Open package control then type install, hit ENTER. Then type js format and hit ENTER, you're done.
(The package controller will show the status of the installation with success and errors on the bottom left bar of Sublime)
Add the following line to your key bindings (Preferences -> Key Bindings User)
{ "keys": ["ctrl+alt+2"], "command": "js_format"}
I'm using CTRL+ALT+2, you can change this shortcut key whatever you want to. So far, JsFormat is a good plugin, worth to try it!
Hope this will help someone.
For me, the HTML Prettify solution was extremely simple. I went to the HTML Prettify page.
Needed the Sublime Package Manager
Followed the Instructions for installing the package manager here
typed CMD+SHIFT+P to bring up the menu
Typed prettify
Chose the HTML prettify selection in the menu
Boom. Done. Looks great
There's a plugin called SublimeHtmlTidy which works pretty well
https://github.com/welovewordpress/SublimeHtmlTidy
Simply go to
Edit -> Tag -> Auto-format tags on document
I created a Package called HTMLBeautify that does a decent job of reformatting HTML. I based it off of a Perl script I found back in 1997—I updated it to work with all the new fangled modern tags. :)
Check it out and let me know what you think!
https://github.com/rareyman/HTMLBeautify
I think this is what you're looking for:
https://github.com/victorporof/Sublime-HTMLPrettify
I am yet to have the privilege to comment so this is simply additional information related to #peter's answer above answer.
I found HTML did not align as expected if IE conditional comments in the header were not completely in-line e.g. flush to the left:
<!--[if lt IE 7]>
<p class='chromeframe'>Your browser is <em>unsupported</em>. Upgrade to a different browser or install Google Chrome Frame to experience this site.</p>
<![endif]-->
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
There is a nice open source CodeFormatter plugin, which(along reindenting) can beautify dirty code even all of it is in single line.
I'm using tidy together with custom build system to prettify HTML.
I have HTMLTidy.sublime-build in my Packages/User/ directory:
{
"cmd": ["tidy", "-config", "$packages/User/tidy_config.cfg", "$file"]
}
and tidy_config.cfg file in the same directory:
indent: auto
tab-size: 4
show-warnings: no
write-back: yes
quiet: yes
indent-cdata: yes
tidy-mark: no
wrap: 0
And just select build system and press CTRL+B or CMD+B to reformat file content. One minor issue with that is that ST2 does not automatically reload the file so to see the results you have to switch to some other file and back (or to other application and back).
On Mac I've used macports to install tidy, on Windows you'd have to download it yourself and specify working directory in the build system, where tidy is located:
"working_dir": "c:\\HTMLTidy\\"
or add it to the PATH.
you can set shortcut key F12 easy!!!
{ "keys": ["f12"], "command": "reindent" , "args": { "single_line": false } }
see detail here.
HTML-CSS-JS Prettify - Hands down the best.
Install Package Control
⌘ + left shift + p (or ctrl + alt + left shift + p) -> Package Control: Install Package
Enter HTML-CSS-JS Prettify
Install node
Restart Sublime Text
Enjoy.

Change or disable modifier key (alt) which activates the application menubar in Sublime Text 3 Linux

I am trying to use the package "Alternate VIM Navigation" in ST3 on Linux Ubuntu, but the alt+i and alt+h keybindings bring up the find and help menus rather than their movement keybindings:
{ "keys": ["alt+i"], "command": "move", "args": {"by": "lines", "forward": false}},
{ "keys": ["alt+h"], "command": "move_to", "args": {"to": "bol", "forward": true}},
I have been able to disable the alt key from displaying the application menubar using CompizConfig Settings Manager, but the alt+i still brings up the find menu (and likewise for alt+h).
I have looked in many places for an answer to this, but have found nothing that works for ST3 in Linux. Here are some related answers for OSX and Windows, and an answer in Ubuntu that suggests the CompizConfig Settings Manager:
https://askubuntu.com/questions/553687/change-or-disable-modifier-key-alt-which-activates-the-application-menubar
Change behavior of Alt key in Sublime Text 2
Stop Alt key bringing up the menu in Sublime Text 2
Any solution to this in ST3 for Linux would be much appreciated!
This worked for me:
Open Sublime's packages directory by going to Preferences > Browse Packages.
Open the User directory and create a file called Main.sublime-menu
Paste the following in:
[
{
"caption": "Help",
"mnemonic": "",
"id": "help"
}
]
Save the file and enjoy!
I found a bit of a strange workaround...
I have a sublime text package called "SubRed" which has a file "Main.sublime-menu" (it's in .config/sublime-text-3/Packages/SubRed - I manually installed the package).
To disable the menubar all I have to do is:
ctrl+shift+p view: toggle menu (which does not disable the menu by
itself for some reason),
open the Main.sublime-menu file in sublime,
save it.
Then voila, the menu bar is gone and I can finally use my Alternate Vim package key bindings without conflicting with the alt+[menubar mnemonic].
To get the menu bar back if needed, just simply do ctrl+shift+p view: toggle menu.
If anyone could suggest a better solution based on this (which doesn't involve a random 3rd party package) that would be much appreciated!
The ideal solution would be to not have to disable the menubar, but get it to work like windows where user or package defined st3 keybindings take precedence over default or system bindings. So if "alt+i" is defined by the package as "move up a line", then it no longer opens the "Find" menu, but actually (eureka!) moves up a line! But opening the "Find" menu is still possible with "alt, i" in sequence.

Sublime Text: File remains in tab even after deleted

When I delete a file that I don't need anymore, but then I have to close the tab manually. It is irritating.
Every time, I have to delete the file and then close the tab by confirming the discard changes.
Is there a way to delete the file in one shot.
Please Note: This happens in my MacBook laptop.
If you use the Side​Bar​Enhancements plugin, there is an option for that:
{
"close_affected_buffers_when_deleting_even_if_dirty": true
}
Make sure to add this to the correct settings file:
Preferences >> Package Settings >> Side Bar
I am not 100% clear on the details of your question. Apologies if this answer does not match what you are trying to ask.
Assuming you do not already have the file open this behaviour is a side effect of the choice to preview the file on click.
If this is the use case you are asking about then there is an answer.
If you look in Preferences -> Settings - Default and search for preview you should find this:
// Preview file contents when clicking on a file in the side bar. Double
// clicking or editing the preview will open the file and assign it a tab.
"preview_on_click": true,
This means clicking on the file to delete it causes it to be opened for preview and after deleting the file you also need to close the preview tab.
If you wish to change this behaviour open this file Preferences -> Settings - User and add this line:
"preview_on_click": false,
Then you should not open a preview and therefore will not need to close it after deleting the file.
If you already have the file you are deleting open for editing this will not cause the behaviour you are looking for.
There is an issue, so in order to don't make a link-only answer, I just paste here the main info :
Sublime Forum Question : Close tab after delete file?
Sublime Forum : https://www.sublimetext.com/forum/viewtopic.php?f=2&t=11686
Sublime Forum Answer :
You can do this with a plugin. I didn't really test this much, so you
may want to test on non critical stuff first. It does just close the
view, so worst case is that you lose some existing work. That being
said, I'm pretty sure it works fine.
import sublime_plugin
import os
class MyEvents(sublime_plugin.EventListener):
def on_activated(self, view):
if view.file_name():
if not os.path.exists(view.file_name()):
view.set_scratch(True)
view.window().run_command("close")
There's a plugin for this:
Plugin's Github Page
Seems like it should be a toggleable option.
This was annoying me so much, I created a plugin for it
https://gist.github.com/michaelkonecny/bb5a0d1cf43698c0ebe8673f92324ea3
Just download the close_deleted_files.py file and save it to
%AppData%\Roaming\Sublime Text 3\Packages\User (or similar path on Mac).
This is how the plugin works:
whenever a view is focused, it goes through the filenames of all the tabs in that window and closes those, whose files do not exist.
Extending #jwpfox answer
Below works for me:
Go to -> Top Menu -> Sublime -> Preferences -> Settings
Here Primary Preferences.sublime-settings file is not editable
when you click on settings, so two pages will open, now add the flag on the second page like below .. it will override the primary setting.
Alternatively, you can add the flag in below location file as well directly :
Packages/User/Preferences.sublime-settings
Add flag as
"preview_on_click": false,
The entire file looks like the below:
{
"ignored_packages":
[
"Vintage",
],
"preview_on_click": false,
}

Sublime 2 text - build during saving a .js file

Please, is there an option, how to disable auto-build, when i am trying to save a .js file?
I was elaborating a node.js + express tutorial, and all the time I've saved the file, the build was starting the node.exe binary, what is something that i dont want, only solution was to tick the Build system for example for JSLint, but it still tries to build when I'm saving a file.
I know there is an tick option in Tools -> Save all on Build, but i cant find the inverse option - disable Build all on save.
I've installed the Node package for Sublime 2, and even when its disabled the build system Nodejs trys to build during the saving proces (ctrl+s)
thanks for all hints!
Here are my custom user packages:
"installed_packages":
[
"Dart",
"JavaScript Console",
"JavaScript Snippets",
"JSLint",
"Mocha Runner",
"Mocha Snippets",
"Nodejs",
"Package Control",
"Require Node.js Modules Helper",
"sublime-jslint"
],
This problem was caused by the nodejs package for sublime text 2 - after removing the package completly (not just disabling) I got an error msg when trying to save the app.js
pressed CTRL+S error: Error trying to parse build system: No data in
C:\Users\username\AppData\Roaming\Sublime Text
2\Packages\Nodejs\Nodejs.sublime-build:1:1
Problem solved, but I still don't know, why sublime was calling nodejs.sublime-build direct after saving the app.js file.
Strange behavior, maybe a bug or a unwanted feature (When a file is saved, the pre-set build system is called direct after the save)
Problem solved by removing the whole package.
If you go to the Tools menu, does the Build option have the shortcut Ctrl-S next to it? If so, your key-mapping probably got messed up at some point. Put the following line in your Key Bindings - User file (in the Preferences menu) and save it by selecting File -> Save (double check that its shortcut is still Ctrl-S as well).
{ "keys": ["ctrl+b"], "command": "build" },
Remove the , at the end if it's the last (or only) line in your user keymap.
You can go to Preferences -> Package Settings and through the menu options for each entry, looking for additional keymap definitions. Also, check Preferences -> Key Bindings (Default) and search for build to see if it got changed there to ctrl+s. If so, feel free to change it back to b.
Have you verified "save" is actually being run on ctrl+s? If not, open up the console ctrl+backtick and enter sublime.log_commands(True) Then press ctrl+s If save is being run, you should see command: save. If not, one of the plugins is grabbing the ctrl+s keybinding before it falls back to default.
If save is running, on of the plugins probably has an on_post_save or on_pre_save listener that is kicking off the build. I checked what I thought would be most likely (Mocha Runner) and it does have an on_post_save listener. I don't know if that's what you are seeing, but it would certainly explain it. Try disabling the plugins and rerunning the save to see if that is the case. If it is, you may want to create an issue on whatever plugin, asking them to make the "build on save" optional.

Resources