Set encoding permanently in Visual Studio Code - visual-studio-code

I am using Visual Studio Code to write a LaTeX file with the LaTeX Workspace plugin.
However everytime that I open VS Code it insists that the encoding of the TeX file is UTF-8 and makes all the special characters go bezerk, but for some reason TeX Live doesn't compile in that encoding even if I convert it. Since another person is using the file too and their editor is set in Windows 1252 encoding, I want to keep using that.
How to set a encoding to a file permantly (or to an extension) in VS Code?

There are language-specific configurations. CTRL-Shift-P and see "Preferences: Configure Language Specific Settings... However, I do not see a LaTex choice there. But you may because of the LaText Plugin. So you could do something like:
{
"[latex]": {
"files.encoding": "windows1252"
}
}
If you don't see one perhaps you could associate your file extension (.tex?) with one on the list and then the above setting?
I assume you have
{
"files.autoGuessEncoding": false
}
already set to false - the default. WTH, try "true".
And see Allow to set files.encoding as language specific setting for files on startup so the lanuage-specific setting should work better on start-up.

Your settings.json per user or per workspace can contain an encoding directive.
If you want Java files opened in UTF-8,
then the following has no effect
"files.encoding" : "utf8",
but this works
"[java]": {
"files.encoding": "utf8"
}

The existing answers show a possible solution for single files or file types. However, you can define the charset standard in VS Code by following this path:
File > Preferences > Settings > Encoding > Choose your option
This will define a character set as default.

VSCode set default file encoding
Sven Eschlbeck's answer illustrated:
The following page will be opened. There are many settings. To get to the desired item without scrolling through all entries, type "Encod" in the search box. Observe that the item "Files: Encoding" is presented to us. Now we can change the setting.
Tips to share with you: "GB18030" applies fairly well universally for source code files containing Chinese characters.
More tips:
The encoding being applied to the current file is shown in the status bar. Mouse right-click this to call up the options as shown.
Here, you can switch encoding ad-hoc.

Having autoGuessEncoding true in USER and autoGuessEncoding false, "files.encoding": "windows1250" in WorkSpace was still giving me windows1252.
I do not uderstand why User overchanged WorkSpace. I have to disable autoGuessEncoding also in USER to finally get "files.encoding": "windows1250" work everytime.
So you can face the same issue and this could help.

Related

VSCode individualize every instance? [duplicate]

Is it possible to show the last folder in the title bar? If you have multiple instances of VS Code open, it is difficult to distinguish between them from the task bar. If both instances are open on say a file called 'main.ts', you will see 'main.ts' in the taskbar item.
Currently, the title would be [filename open] - [folder open] (e.g main.ts - angular2-training. Is it possible to invert them to become [folder open] - [filename open] (e.g angular2-training - main.ts?
Use window.title in user/workspace settings
The documentation is here with the full list of options of what can be shown. It's quite flexible.
In your case, to display angular2-training - main.ts you can use this
{
"window.title": "${rootName}${separator}${activeEditorShort}"
}
Older VS Code versions
The above only works in v1.10 and up. Here's how to do it in older versions:
v1.9, v1.8 - "window.showFullPath": true shows the full path to the current file, so you can at least see the project folder. Note this config is unsupported after v1.10
v1.7 and below - it's not possible
On version 1.13
Go to settings, inside UserSettings add this line to the json blob:
"window.title": "${activeEditorLong}"
On version 1.41.1
based uploaded image:
1,2: Go to Setting
3: Search windows title in search box
4: Type this statement in windows title box:
${dirty}${separator}${rootName}${separator}${activeEditorShort}
If you want to be able to identify which project you are working on by looking at the window title bar, one option is to set "window.title" to a custom value in the workspace settings file at
/.vscode/settings.json
If the file doesn't exist, create it, then add the following to it:
{
"window.title": "<PROJECT NAME> : ${rootName}${separator}${activeEditorShort}"
}
This is a simple solution that works rather well.
Tested in 1.44
The setting which matches the OPs problem... not being able to tell which VS Code editor is which from the taskbar... is:
"window.title": "${folderName} ${separator} ${activeEditorShort}"
I prefer the simpler
"window.title": "${folderName}"
${activeFolderShort} and friends, don't do what I want, as these follow the folder the active file is in. Whereas I want the folder of the whole "project" shown at all times.
Also, when browsing from the taskbar, I don't care what file is active - it is just noise. I care about the project (i.e. folder). On many occasions, every open VS Code will "main.rs" as the active file, so it is pointless to show it!
Editing the settings in json format even includes intellisense now, so you can see all the options without even having to look them up, and they appear as soon you save the settings file. No need to reload. Awesome!
v1.31 of vscode added these options to window.title:
There are three new variables that can be used within the window.title
setting:
${activeFolderShort}: The name of the folder the file is contained in.
${activeFolderMedium}: The path of the folder the file is contained
in, relative to the workspace folder.
${activeFolderLong}: The full
path of the folder the file is contained in.
In addition of the setting:
"window.title": "${rootName}${separator}${activeEditorShort}"
You now can configure the separator as well with VSCode 1.45 (April 2020)
Allow customize the window title separator
A new setting window.titleSeparator allows to change the separator that is used in the window title.
By default a dash is used.
Just some tweaks i found out:
// will not work on workspace settings.json -> only global
"window.titleBarStyle": "custom",
// show only the name of the workspace folder in the title bar
"window.title": "${folderName}",
// remove the useless icons on the top-right
"window.commandCenter": false,
// make left & top green :-)
"workbench.colorCustomizations": {
"activityBar.background": "#1e2127",
"activityBar.foreground": "#95C085",
"titleBar.activeBackground": "#165900",
"titleBar.activeForeground": "#ffffff",
},

Where is the Terminal's formatting defined in VS Code?

I cannot locate the settings or other configurations that define the colors and other formatting shown in VS Code's Terminal output. I'd like to mimic or use these settings elsewhere, such as in word processing software, HTML/CSS, or simply a Language Mode when copying & pasting the output into a new VS Code file.
Where is this formatting defined? Also, how can I keep this formatting intact when using the text elsewhere?

VsCode: Is there a keyboard shortcut How to make VS Code treat files without extension as a certain language?

Is there a keyboard shortcut How to make VS Code treat/reopen/reload files without extension as a certain language?
Just to be clear, here's my use case:
Sometimes I have a big JSON I need to read so I copy it in VsCode new file but since it's a new file I have to save it a s JSON extension to read it in the correct format. So my question is: Is there a way to specify the language for this new file(without extension) to open it as JSON for example?
Thank you
I found these two options:
// The following example associates all files in a folder `somefolder` to PHP:
"files.associations": {
"**/somefolder/*.*": "php"
}
https://code.visualstudio.com/docs/languages/overview#_can-i-map-additional-file-extensions-to-a-language
// The default language mode that is assigned to new files.
"files.defaultLanguage": "html"
https://code.visualstudio.com/docs/languages/overview#_how-do-i-set-the-default-language-for-new-files
Add the lines of your choice to settings.json.
Nevermind guys I found it:
The feature is called Change Language Mode.
The default shortcut is Ctrl+K M if you want to customize it here's the name of the command:
workbench.action.editor.changeLanguageMode
You can also click in the lower right of VSCODE window to change the language mode:

How to set default file type to be All Files(*.*) in VS Code?

Now my default file type of Visual Studio Code is Plain Text.
If I save a new file with name like a.in, it will save as a.in.txt. I have to change the dropdown to All Files.
I find the same problems in github: 1, 2. However, they seem not solve my problem.
This is not possible in the general case in VSCode.
The issue is that you cannot assign "no extension" to a language, and as per the links you mentioned, the All Files (*.*) option is disabled by upstream (electron).
Therefore, you will either have to remove the extension manually, OR you can create the file first (using the terminal, Explorer, an extension, etc.) and then open that existing file.
There is a way to change the default extension (but not to All Files)
Add the following line to your settings.json
"files.defaultLanguage": "<language>",
Replace <language> with the language of your choice.
Now, whenever you make a new a file, the default file language will be <language>.
A special value for <language> is ${activeEditorLanguage} which is the language of the file last opened (useful if, say, you copy a piece of code from one file to save as another).
Unfortunately, this does not fully answer the question, but provides a partial solution.

How can I clean source code files of invisible characters?

I have a bizarre problem: Somewhere in my HTML/PHP code there's a hidden, invisible character that I can't seem to get rid of. By copying it from Firebug and converting it I identified it as  or 'Zero width no-break space'. It shows up as non-empty text node in my website and is causing a serious layout problem.
The problem is, I can't get rid of it. I can't see it in my files even when turning Invisibles on (duh). I can't seem to find it, no search tool seems to pick up on it. I rewrote my code around where it could be, but it seems to be somewhere deeper in one of the framework files.
How can I find characters by charcode across files or something like that? I'm open to different tools, but they have to work on Mac OS X.
You don't get the character in the editor, because you can't find it in text editors. #FEFF or #FFFE are so-called byte-order marks. They are a Microsoft invention to tell in a Unicode file, in which order multi-byte characters are stored.
To get rid of it, tell your editor to save the file either as ANSI/ISO-8859 or as Unicode without BOM. If your editor can't do so, you'll either have to switch editors (sadly) or use some kind of truncation tool like, e.g., a hex editor that allows you to see how the file really looks.
On googling, it seems, that TextWrangler has a "UTF-8, no BOM" mode. Otherwise, if you're comfortable with the terminal, you can use Vim:
:set nobomb
and save the file. Presto!
The characters are always the very first in a text file. Editors with support for the BOM will not, as I mentioned, show it to you at all.
If you are using Textmate and the problem is in a UTF-8 file:
Open the file
File > Re-open with encoding > ISO-8859-1 (Latin1)
You should be able to see and remove the first character in file
File > Save
File > Re-open with encoding > UTF8
File > Save
It works for me every time.
It's a byte-order mark. Under Mac OS X: open terminal window, go to your sources and type:
grep -rn $'\xFEFF' *
It will show you the line numbers and filenames containing BOM.
In Notepad++, there is an option to show all characters. From the top menu:
View -> Show Symbol -> Show All Characters
I'm not a Mac user, but my general advice would be: when all else fails, use a hex editor. Very useful in such cases.
See "Comparison of hex editors" in WikiPedia.
I know it is a little late to answer to this question, but I am adding how to change encoding in Visual Studio, hope it will be helpfull for someone who will be reading this sometime:
Go to File -> Save (your filename) as...
And in File Explorer window, select small arrow next to the Save button -> click Save with Encoding...
Click Yes (on Do you want to replace existing file dialog)
And finally select e.g. Unicode (UTF-8 without signature) - that removes BOM