VSCode settings for json file - remove braces formatting - json

VSCode default autoformatter is formatting .json files with empty objects to a single line, which is not what i want. Basically i try to get away from this:
"settings": {}
To this:
"settings": {
}
Here is my settings.json file in VSCode

The setting JSON > Format: Keep Lines , if enabled, will do what you want.
Keep all existing new lines when formatting.
It will preserve your newline between the braces upon formatting.

Related

Mimic "less -r" when displaying .txt file in HTML

I have a .txt file that contains escape characters. You can't see them when you cat or more or "less -r" the file, but if you vi the file you see the following:
session_cache ^[[27G: 375755
Normal output from "cat" is:
session_cache : 375755
The ^[[27G I believe is a ANSI terminal code for tab maybe? I would like to be able to display this text file in a standard web page without having to see those escape characters.
Is this possible without having to convert the .txt file to HTML and manually remove all the different escape sequences (ie make HTML behave like cat does)?
Dan

replace all selected json objects with a different object

I am using visual studio code Version 1.19.3, and I have 174 occurrences of a specific json object which I would like to replace with a different object. Is there an easy way to do this in visual studio code? find and replace doesn't work because of the tabs.
You can search and replace tabs in vscode but perhaps you have your tabs converted to spaces as your default indentation. If you try Ctrl-Shift-P and "Convert Indentation to Tabs" then search and replace for \t will work as you expect (with the Use Regular Expression button clicked).
Then you could back to indentation with spaces by Ctrl-Shift-P and "Convert Indentation to Spaces" if you wish when you are done.

Sublime Text syntax highlighting regex not working

I use angularJS, and have various directives that follow a naming convention like "app-data-grid", "app-slider", "app-carousel" or "app-compile-some-template", etc. Essentially, it is the normal angular directive naming convention of [app name]-[dash delimited words]. Sublime Text HTML language syntax highlighting doesn't properly match these with its regex. It will highlight "app" in "<app-carousel" or "<app-some-long-directive-name" but will not highlight the entire tag name.
Here is the predefined regex in the HTML.tmLanguage file:
(<)([a-zA-Z0-9:]++)(?=[^>]*></\2>)
I tried adding a dash after the colon of the second matching group:
(<)([a-zA-Z0-9:-]++)(?=[^>]*></\2>)
The second regex worked in a regex tester, but did not work in Sublime Text.
Also, I have downloaded an AngularJS plugin that gave me an AngularJS-HTML language definition... which also has the same problem.
How can I fix the regex so that it matches the full tag name for highlighting?
Go to Preferences >> Settings-User.
On this JSON add to ignored_packages array an iten named "HTML", like this:
"ignored_packages":
[
"Vintage",
"HTML"
]
Save the file.
Now go to Preferences >> Browse Packeges, make a copy of HTML directory and rename it as "HTMLAngularJS".
Enter in to HTMLAngularJS directory and rename the file "HTML.tmLanguage" to "HTMLAngularJS.tmLanguage".
Edit "HTMLAngularJS.tmLanguage" file, find this both Regex:
<string>(<)([a-zA-Z0-9:]++)(?=[^>]*></\2>)</string> Line 45
and
<string>(</?)([a-zA-Z0-9:]+)</string> Line 514
Just add the slash and - after double points, should be like this:
<string>(<)([a-zA-Z0-9:\-]++)(?=[^>]*></\2>)</string>
and
<string>(</?)([a-zA-Z0-9:\-]+)</string>
Save the file and be happy!
Regards!
Use the HTML Extended sublime plugin
Did you add HTML to your ignore_package array in your user settings?
With that entry, you are overriding the default HTML syntax package, therefore forcing sublime to user your HTML.tmLanguage.
I found this answer from BoundinCode where he explains it, and this actually did the trick for me.

Different rulers by file type in Sublime Text 2

Is there a way to tell sublime text 2 to display a column 78 ruler in python and javascript and no ruler in HTML, by default?
Yes! For both a Python and a Javascript file, open it (or just set the syntax for an empty file to Python or Javascript), then click Preferences -> Settings – More -> Syntax Specific – User. Edit that settings file like you would your regular user settings file. Once you're finished, it will look something like this:
{
"rulers": [
78
]
}
Do the same for HTML, but make the "rulers" array empty, i.e.:
{
"rulers": [ ]
}
Subsequently, Javascript and Python files will have a ruler at line 78, whereas HTML will display no rulers. Any settings that you can define in your user settings file can be made specific to a syntax.
Close the file and re-open it if it doesn't take effect. Had to do this with my .py files. Applies for Sublime 3

Command-line HTML formatter that doesn't modify HTML in any way, just indents?

I've been trying to tidy (read: HTML Tidy) up my HTML, but it keeps trying to "fix" my HTML which actually breaks the output. I don't have time to fix all this "invalid" HTML... it renders fine in every browser, I just want to format it so that I can actually read it. Is there such a tool?
Try opening it in vim (a file editor) then use this:
gg=G
That will reindent (=) every line from the first line (gg) to the last (G). It will only work if the new lines already exist. If you need to insert new lines you could add a regex to look for close tags and then insert a new line.
%s/\>/\>\\n/g
%s whole file regex match closing tag > and replace with > new line.
If you're new to vim you can use :wq to write (w)[save] and quit q