Sublime Text 3 HTML files comments are not angle brackets but curly brackets - html

When toggle comments with ctrl+/ on HTML or VueComponent files syntax with Sublime Text 3 the comments that appear are {{-- Comment text --}} instead of the correct ones <!-- Comment text -->.
How to make ST to add correct comments?
Edit as #MattDMo advised in comments below: add the list of installed packages.
"A File Icon",
"All Autocomplete",
"AutoFileName",
"Babel",
"BracketHighlighter",
"Chai Completions",
"Color Highlighter",
"Colorcoder",
"CSS Extended Completions",
"DocBlockr",
"Dockerfile Syntax Highlighting",
"DotENV",
"Edge Syntax Highliter",
"Emmet",
"HTML-CSS-JS Prettify",
"JavaScript & NodeJS Snippets",
"JavaScript Completions",
"JavaScript Snippets",
"JavaScriptNext - ES6 Syntax",
"JSON Reindent",
"LanguageTool",
"Laravel Blade Highlighter",
"LESS",
"MarkdownEditing",
"MarkdownPreview",
"nginx",
"Nunjucks Syntax",
"Package Control",
"PHP Companion",
"PHP Completions Kit",
"PHP-Twig",
"phpfmt",
"PHPGrammar",
"PhpNamespace",
"PHPUnit Completions",
"Select Quoted",
"SideBarEnhancements",
"SublimeCodeIntel",
"SublimeLinter",
"SublimeLinter-annotations",
"SublimeLinter-tslint",
"TypeScript",
"TypeScript Syntax",
"TypescriptCompletion",
"Vue Syntax Highlight",
"Vuejs Complete Package",
"zenburn"

Unfortunately, the only way to tell which package is highjacking your HTML commenting is to put (nearly) all of them in your "ignored_packages" setting, verify that the desired behavior has returned, then start removing packages from "ignored_packages" and see which one triggers the undesired behavior.
You can find (or create) "ignored_packages" in Preferences.sublime-settings in your Packages/User folder. The Packages directory is the one opened when selecting Preferences → Browse Packages…:
Linux: ~/.config/sublime-text-3/Packages
OS X: ~/Library/Application Support/Sublime Text 3/Packages
Windows Regular Install: C:\Users\YourUserName\AppData\Roaming\Sublime Text 3\Packages
Windows Portable Install: InstallationFolder\Sublime Text 3\Data\Packages
You can make the process go a little faster by removing packages from "ignored_packages" three or five at a time, then going down to one by one when the bad behavior comes back. Also, you don't need to ignore clearly innocent packages like Package Control, Zenburn, A File Icon, etc. Good luck!

Related

Can we make use of syntax highlighting feature to remove all comments from a source file in SublimeText?

I have a bunch of source files written in different languages, and I would like to strip all comments from the source files.
While writing regex is certainly an option, depending on the input files, I may have to handle cases where the character to denote comment appears inside string literals. There is also the need to maintain a list of regex for different languages.
The syntax highlighting seems to do quite a good job at highlighting the comments, but there doesn't seem to be any command to remove all comments in the Command Palette.
Is there any way to leverage the syntax highlighting feature in SublimeText to remove all comments from source files in different languages?
Based on nhahtdh's answer, the following plugin should work for both Sublime Text 2 and 3
import sublime_plugin
class RemoveCommentsCommand(sublime_plugin.TextCommand):
def run(self, edit):
comments = self.view.find_by_selector('comment')
for region in reversed(comments):
self.view.erase(edit, region)
Create a new file with Python syntax, and paste the code above into it. Save the file in your Packages/User directory (accessible via Preferences -> Browse Packages...) as remove_comments.py. You can now either run the plugin via the console, or bind a key combination to it. To run via the console, just type
view.run_command('remove_comments')
in the console, and all the comments in the current view will be deleted.
To bind a key combination, open Preferences -> Key Bindings-User and add the following (surround it with square brackets [] if the file is empty):
{ "keys": ["ctrl+alt+shift+r"], "command": "remove_comments" }
Save the file, and you can now hit CtrlAltShiftR (or whatever key combination you choose) and all comments in the current file will be deleted.
Assumption
We will make use of the syntax highlighting rules in Sublime Text to remove all comments, so the method below works only if the syntax highlighting works correctly for the language of your source file.
For most languages, the syntax highlighting rules do quite a good job at recognizing the comments. However, it would be best if you take another look at your files to see if there is any anomaly in syntax highlighting.
The current method only works for Sublime Text 2.
Solution
Open the Console via View > Show Console or the key combination Ctrl+`
Copy and paste the following commands line by line:
e = view.begin_edit()
len([view.erase(e, r) for r in reversed(view.find_by_selector('comment'))])
view.end_edit(e)
After the last command, the edit will be applied and all comments will be removed.

How to negate 'remove all folders' mistake in Sublime Text project

In Sublime Text (2 & 3) I find I accidentally remove all folders from the project when I don't want to (this option is poorly placed in the menu, with no obvious undo or warning and is arguably similar to a 'clear' button on a form).
I often have many folders open in a project each one a leaf in the folder tree structure, which is my workflow, so naturally this is a nasty break in my work if it's accidentally triggered!
I would like to know if I can either disable this option or undo it if I accidentally trigger it?
Aside from a backup, a version control system, or a versioning feature on your file system, there is unfortunately no way of undoing the "Remove all Folders from Project" command, because as soon as the command is fired the folders are removed from the .sublime-project file, and the file is saved. However, there is a way to disable the command. The methods vary between Sublime Text 2 and 3, so I'll go over 2 first.
In Sublime Text 2, click on Preferences -> Browse Packages... to open the Packages folder, whose location varies by operating system. Go into the Default folder, and open Main.sublime-menu in Sublime (it's a JSON file). Search for "close_folder_list" and find the line that looks like this (it's line 737 in version 2.0.2):
{ "command": "close_folder_list", "caption": "Remove all Folders from Project", "mnemonic": "m" },
Now, you can either simply delete the entire line, or comment it out by putting // as the first characters on the line. Save the file, then click on the Project menu to see that the option is gone.
If you're using Sublime Text 3, you'll need a workaround to access the Packages/Default folder and its contents, as in this version most of the packages that you would normally have seen in the Packages directory in ST2 are zipped into .sublime-package files and stored elsewhere. However, there's a plugin for that! Make sure you have Package Control installed, then open the Command Palette, type pci to bring up Package Control: Install Package, and search for PackageResourceViewer. Install it, open the Command Palette again, type prv, and select PackageResourceViewer: Edit Package Resource. Scroll down to Default, click on it or hit Enter, then scroll down to Main.sublime-menu and select it to open it for editing. You can now follow the instructions above to find the line containing "close_folder_list" (it should be line 795) and either delete it or comment it out.
If you'd like to keep the menu item, but move it to a different spot, you can do that as well. For example, if you'd like it at the very bottom of the menu, separated by a divider, delete the original line, put the cursor below the "refresh_folder_list" line, and paste in the following:
{ "caption": "-" },
{ "command": "close_folder_list", "caption": "Remove all Folders from Project", "mnemonic": "m" },
so it looks like this:

Set syntax for a specific file name in Sublime Text 2/3

I have a program that uses a file called user.cfg to get its user defined configuration settings. The odd thing is that they chose the syntax for this file to be Tcl (it's not odd that it is Tcl, it's odd they chose the .cfg extension instead of .tcl). So, when I open this file in Sublime Text, it doesn't know what syntax highlighting scheme to choose.
What I would like to do is set the syntax highlighting for user.cfg to Tcl, but not all .cfg files to Tcl.
I have seen this question which is very similar to mine, except in that case the special file name had no extension so Sublime Text knew to assign Ruby highlighting to only that one file. Unfortunately, I have an extension so the solution given there will not work for me.
Is there any known way to get Sublime Text base a highlighting scheme on the full filename?
Take a look at the ApplySyntax plugin.
The previous answer is completely true; however, I thought it would be better to have it here all in one place rather than going on another webpage to find the list of procedure to apply it
Sublime text 3
This is found here
Ensure Package Control is installed. Instructions are found here.
In Sublime Text, press Ctrl+Shift+P (Win, Linux) or Cmd+Shift+P (macOS) to bring up the quick panel and start typing Package Control: Install Package.
Select the command and it will show a list of installable plugins.
Start typing ApplySyntax; when you see it, select it.
Restart to be sure everything is loaded proper.
Enjoy!

How do I edit HTML.tmLanguage in sublime on mac osx

I'm to change it to support non-quote id, as in:
<div id=someId></div>
I found this
http://www.sublimetext.com/forum/viewtopic.php?f=3&t=8129
But am having issues finding where to edit the tmLanguage file
Don't listen to Jamie's answer. You should never be editing the Pristine packages. Instead, you can find all of Sublime Text's packages and grammar files in ~/Library/Application Support/Sublime Text/Packages or, from within Sublime Text, go to Sublime Text > Preferences > Browse Packages. However, if you edit HTML.tmLanguage from within the HTML folder, your changes will be overridden when Sublime Text is updated. To prevent this, duplicate the HTML folder and renaming it to Better HTML. Then in your User Settings (Preferences > Settings - User) add the following:
"ignored_packages":
[
"HTML",
"Vintage"
],
By ignoring the default HTML package, Sublime Text will be forced to use your version of the HTML.tmLanguage file and your changes will be preserved.
You can find the HTML.tmLanguage file by going to /Applications and then control/right click on Sublime Text 2.app and select 'Show Package Contents'. Then navigate to /Contents/Mac OS/Pristine Packages/.
Inside that folder, you should see a collection of sublime-package files. Find HTML.sublime-package and rename it to HTML.zip. You should then be able to extract the archive, just like any other zip folder, and inside you should find all assests related to Sublime's HTML package - including the HTML.tmlanguage.
Make sure to recompress and then rename the folder back to .sublime-package after making your edits!
EDIT: I have since recognised that this is incorrect, the Pristine Packages should never be edited. Follow BoundinCode's answer instead!

Formatting code in Notepad++

Is there a keyboard shortcut to format code in Notepad++ ?
I'm mainly working with HTML, CSS and Python code.
For example:
<title>{% block title %} {% endblock %}</title>
<link rel="stylesheet" href="/media/style.css" type="text/css" media="screen" />
</head>
To:
<head>
<title>
{% block title %}
{% endblock %}
</title>
<link rel="stylesheet" href="/media/style.css" type="text/css" media="screen" />
</head>
I remember Visual Studio doing it with Ctrl+K+D and NetBeans having the feature too but can't find it within Notepad++, if it can even do it.
TextFX -> HTML Tidy -> Tidy: Reindent XML
Remember to have the HTML code selected before you do this.
there is such a plugin as UniversalIndentGUI, it can be installed right from the plugin manager and has possibilities to reindent the most used programming languages.
If you go to TextFX menu and go to TextFX Edit, you will see a menu item Reindent C++ Code.
That will also format C# code.
ANSWER AS OF June 2019
Install the XML Tools plugin from the Plugin Admin (in Notepad++ 7.7 at least)
Then click Plugins -> XML Tools -> Pretty Print (XML Only with Line breaks)
That did it for me.
Here is a list of the available shortcuts in Notepad++.
In case your desired functionality is not available, you are able to define own macros and assign them to a custom shortcut (i am not used to use macros).
UPDATE: I will post the shortcuts here in case the link gets invalid:
Shortcut Command
Ctrl-C Copy
Ctrl-X Cut
Ctrl-V Paste
Ctrl-Z Undo
Ctrl-Y Redo
Ctrl-A Select All
Ctrl-F Launch Find Dialog
Ctrl-H Launch Find / Replace Dialog
Ctrl-D Duplicate Current Line
Ctrl-L Delete Current Line
Ctrl-T Switch the current line position with the previous line position
F3 Find Next
Shft-F3 Find Previous
Ctrl-Shft-F Find in Files
Ctrl-F3 Find (volatil) Next
Ctrl-Shft-F3 Find (volatil) Previous
Ctrl-Shft-I Incremental Search
Ctrl-S Save File
Ctrl-Alt-S Save As
Ctrl-Shft-S Save All
Ctrl-O Open File
Ctrl-N New File
Ctrl-F2 Toggle Bookmark
F2 Go To Next Bookmark
Shft-F2 Go To Previous Bookmark
Ctrl-G Launch GoToLine Dialog
Ctrl-W Close Current Document
Alt-Shft-Arrow keys or Alt + Left mouse click Column Mode Select
F5 Launch Run Dialog
Ctrl-Space Launch CallTip ListBox
Alt-Space Launch Word Completion ListBox
Tab (selection of several lines) Insert Tabulation or Space (Indent)
Shft-Tab (selection of several lines) Remove Tabulation or Space (outdent)
Ctrl-(Keypad-/Keypad+) or Ctrl + mouse wheel butto Zoom in (+ or up) and Zoom out (- or down)
Ctrl-Keypad/ Restore the original size from zoom
F11 Toggle Full Screen Mode
Ctrl-Tab Next Document
Ctrl-Shft-Tab Previous Document
Ctrl-Shft-Up Move Current Line Up
Ctrl-Shft-Down Move Current Line Down
Ctrl-Alt-F Collapse the Current Level
Ctrl-Alt-Shft-F Uncollapse the Current Level
Alt-0 Fold All
Alt-(1~8) Collapse the Level (1~8)
Alt-Shft-0 Unfold All
Alt-Shft-(1~8) Uncollapse the Level (1~8)
Ctrl-BackSpace Delete to start of word
Ctrl-Delete Delete to end of word
Ctrl-Shft-BackSpace Delete to start of line
Ctrl-Shft-Delete Delete to end of line
Ctrl-U Convert to lower case
Ctrl-Shft-U Convert to UPPER CASE
Ctrl-B Go to matching brace
Ctrl-Shft-R Start to record /Stop recording the macro
Ctrl-Shft-P Play recorded macro
Ctrl-Q Block comment/uncomment
Ctrl-Shft-Q Stream comment
Ctrl-Shft-T Copy current line to clipboard
Ctrl-P Print
Alt-F4 Exit
Ctrl-I Split Lines
Ctrl-J Join Lines
Ctrl-Alt-R Text Direction RTL
Ctrl-Alt-L Text Direction LT
F1 About
The latest plugin is tidy2, which can be installed through Plugins>Plugin Manager>Show Plugin Manager.
I suggest editing config 1 and setting quote-marks: no, especially if you have script that makes use of quotes.
Also, tidying more than once can result in inserting ampersands the first time and then replacing the ampersands the second time. You may want to play with the config to get it to where you need it.
For JavaScript Formatting I use Notepad ++ JSMin Plugin.Quite Handy
This isn't quite the answer you were looking for, but it's the solution I came to when I had the same question.
[update - I'm using vscode now for everything. I think it works better in a lot of cases.]
I'm a pretty serious Notepad++ user, so don't take this the wrong way. I have started using NetBeans 8 to develop websites in addition to Notepad++ because you can set it to autoformat on save for all your languages, and there are a ton of configuration options for how the formatting looks, down to the most minute detail. You might look into it and find it is a worthy tool to use in conjunction with notepad++. It's also open source, completely free, and has a bunch of plugins and other useful things like automatically compiling Sass if you use that too. It's definitely not as quick as NP++ so it's not great for small edits, but it can be nice for a long coding session.
In my notepad++, it seems TextFX needs a perl environment to format HTML files. Tidy2 demands nothing so I think it's more handy.
If all you need is alignment, try the plugin called Code Alignment.
You can get it from the built-in plugin manager in Notepad++.
We can use the following shortcut in the latest version of notepad++ for formatting the code
Alt + Ctrl + Shift + B
In Plugins > Plugin Admin > Search 'XML Tools' > Install.
The window will restart and install XML Tools under plugins.
Open your file and click Ctrl + Alt + Shift + B
No. Notepad++ can't format by itself. Formatting can easily be accomplished in many IDEs like Eclipse, NetBeans, Visual Studio [Code].
Another Potential Solution
Okay, so it's been 12 years since this question was asked. I think that I've found a another acceptable solution, that is perhaps better for formatting files, using Prettier.
What is Prettier?
Prettier is described as: "an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary."
Prettier Supports the Following Languages
HTML
CSS, Less, and SCSS
JavaScript
TypeScript
JSX, Angular, Vue
JSON, Markdown, YAML
And a few others.
If You Want to Use Other Languages, You Can Either Use:
Plugins made by the community to Prettier, which allow support for other formats such: Java, Rust, PHP, SQL, and others.
Non-Prettier formatters supporting other languages such as clang-format (npm version) (C / C++ / Java / JavaScript / JSON / Objective-C / Protobuf / C#), or Black (Python).
How To Install
You're going to need to install Node.js for this tutorial.
Note: There may be other work arounds for using the subsequent
mentioned software without using Node.js. But to keep this tutorial
simple and the fact that Node.js already carries widespread
familiarity among developers, I'm going to be using this software
without explaining how to install it.
After installing Node.js, install prettier globally to your system, allowing yourself to run prettier anywhere from the command line.
# NPM is the package manager used by Node.js
# And --global allows you to use prettier anywhere on your local computer.
npm install --global prettier
# To install other plugins (example):
npm install --g prettier-plugin-rust prettier-plugin-java
# To Install clang-format using NPM
npm install -g clang-format
# Usage Examples
prettier --write jquery-min.js # Formatting a JavaScript file
clang-format -i Test.cpp # Formatting C++ file
On Notepad++, install a plugin called NppExec from Menu> Plugins Admin...> Available> NppExec.
You can now run NppExec by either pressing F6 or by clicking Menu > Plugins > NppExec > Execute NppExec Script...
Now you should have a window pop up, giving you the option of executing a command.
You can either use prettier on a (1) specific file or (2) all files in a folder or (3) all files in a directory recursively.
You can always reload a file after it's better overwritten by Prettier using Ctrl+R, and enabling the following setting: Menu > MISC. > Update silently.
Commands and Screenshots of NppExec + Prettier.
REM Using Prettier on Current File (use cmd or powershell /c)
cmd /c prettier --write "$(FULL_CURRENT_PATH)"
REM Using Prettier on Current Folder (a single asterisk)
pwsh /c prettier --write "$(CURRENT_DIRECTORY)\*"
REM Using Prettier on Current Directory Recursively (double asterisk)
pwsh /c prettier --write "$(CURRENT_DIRECTORY)\**"
Install NppExec Plugin
Running NppExec Plugin
Executing Commands on NppExec
NPP+ v7.9.1 with the latest version of XMLTools can't format exported VBA code from Office 2016/2019 Word. It puts all the code on the same line since it strips the CRLF out. Moreover, when you enable "auto validation" it errors out on the first VBA line that is, Attribute VB_Name = "The VBA module name". So any of the xml tool validations apparently can't be used for VBA validation.