Formatting Sublime Text 2 Formatting

First let me say that I come from Microsoft, and Visual Studio is my bread and butter. It has a command (keybind is optional) that automatically formats any code syntax. The same command works in HTML, CSS, Javascript, C #, etc.

I tried plugins for ST2, and so far I have found that most of them do not work in the Windows window, and if they do, this is for a specific purpose, like Javascript.

I tried (and, if necessary, discovered problems):

https://github.com/victorporof/Sublime-HTMLPrettify

https://github.com/jdc0589/JsFormat (this one actually works)

https://github.com/welovewordpress/SublimeHtmlTidy

Do Windows ST2 users have anything that works for CSS / HTML / Javascript formatting, preferably with one shot?

Edit: Since this question raises many views without activity, I will say that I'm still looking for a plugin that can format different types of script inside the same command.

October 2013 Still have not found anything that covers JS + CSS + HTML, but I decided on JsFormat , because it is by far the most efficient and error-free with the least configuration for JavaScript only.

+48
sublimetext2 sublimetext prettify
Apr 04 2018-12-12T00:
source share
4 answers

I can't speak for the second or third, but if you install Node first, then Sublime-HTMLPrettify works very well. You must configure your own key shortcut after installing it. One thing I noticed on Windows might need to change its path for Node in the% PATH% variable if it is already long (I think the limit is 1024 for the% PATH% variable, and everything is ignored after that.)

There is a Windows error, but there is a fix for it in the problems. You will need to edit the HTMLPrettify.py file - https://github.com/victorporof/Sublime-HTMLPrettify/issues/12

+8
Apr 24 2018-12-12T00:
source share

A similar option in Sublime Text is the built-in Edit->Line->Reindent . You can put this code in Preferences -> Key Bindings User :

 { "keys": ["alt+shift+f"], "command": "reindent"} 

I use alt + shift + f because I am a Netbeans user.

To format the code, select everything by pressing ctrl + a and the key combination. Excuse me for my bad english.




Or, if you don't want to select everything before formatting, add an argument to the command instead:

 { "keys": ["alt+shift+f"], "command": "reindent", "args": {"single_line": false} } 

(as per @Supr comment below)

+99
Jan 22 '13 at 2:08
source share

Sublime CodeFormatter supports formatting PHP, JavaScript / JSON / JSONP, HTML, CSS, Python. Although I haven't used CodeFormatter for a long time, I was impressed with the JS, HTML, and CSS "decorating" features. I have not tried using it with PHP (I am not involved in PHP development) or Python (with which I have no experience), but both languages ​​have many parameters in the .sublime-settings file.

However, however, the settings are not so easy to find. On Windows, you will need to go to %AppData%\Roaming\Sublime Text #\Packages\CodeFormatter\CodeFormatter.sublime-settings . Since I don't have a Mac, I'm not sure where the settings file is on OS X.

Regarding the shortcut key, I added this key binding to my " Key Bindings - User " file:

 { "keys": ["ctrl+k", "ctrl+d"], "command": "code_formatter" } 

I use Ctrl + K , Ctrl + D because this is what Visual Studio uses for formatting. You can change it, of course, just remember that what you choose may conflict with some other function key combination.

Update:

Sublime Text CodeFormatter seems to have made access to the .sublime-settings file .sublime-settings . If you install CodeFormatter using the package management module, you can access the settings using Preferences -> Package Settings -> CodeFormatter -> Settings - Default and override these settings using the menu item Preferences -> Package Settings -> CodeFormatter -> Settings - User .

+13
Apr 25 '13 at 13:25
source share

This answer may not be exactly what you are looking for, but it will fomat any language with the same keyboard shortcut. The solution is special language keyboard shortcuts .

For each language you want to format, you must find and download a plugin for it, for example, the html formatter and the C # formatter. And then you map the command for each plugin with the same key, but with a different context (see Link).

greets

0
Aug 01 '17 at 18:44
source share



All Articles