Any way to have workspace/folder settings ONLY apply to files in that workspace/folder and not random files outside the workspace? - visual-studio-code

I know about workspace settings. My issue is that workspace settings also apply to any files that are opened not in that workspace. Example:
"editor.formatOnSave": true // put this in some workspace settings.
open a file not in that workspace (maybe in a different project) in the same window. This happens when I type $ code ~/someFile.txt
When I save that file, it gets formatted when it shouldn't.
Any workarounds?

Specifically for saving a file without formatting, try new command for saving without formatting. Just added in v1.28.0:
The new command Save without Formatting
(workbench.action.files.saveWithoutFormatting) can be used to save a
file without triggering any of the save participants (for example,
formatters, remove trailing whitespace, final newline). The default
keybinding is Ctrl+K S. This is useful when editing files outside your
normal projects, which may have different formatting conventions.

Related

VSCode emmet issue after changing case for file name

I am new to using VSCode and emmet for expanding filenames, etc.
Currently, I'm working on a React project and found an issue where, for example:
I create a files named, say, myfile.jsx for my MyFile component
Realize I want the file name capitalized to match the component name, so I rename it to MyFile.jsx
When trying to use emmet to import the file to use the component in, say, my App.js it imports the old filename myfile.jsx (without the updated casing).
In other words, emmet is not picking up in the change in casing for file names.
Is there a way to somehow refresh the cache for emmet / have this update without having to restart VSCode?
Thanks!

How to add Format config file to VSCode workspace using Ionide

I want to add specific workspace setting for Formatting for F#
I see that Ionide for VSCode uses FsAutoComplete which in turns uses Fantomas as the Formatter and that Fantomas has config file support (not documented), but I tried to add .fantomas-config and fantomas-config.json in the root of my project and the config file was ignored.
Ultimately what I want to achieve is:
preserve new lines made by me.
set the "word wrap" column length
Other common formatting options like indentation etc.

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.

Change title of untitled tab in Visual Studio Code

I'm building a VS Code extension which includes changing the name/title of untitled-1 tab (unsaved file).
I tried running the below code in debugger console of extension but it didn't reflect in the editor:
vscode.workspace.textDocuments[0].fileName="myFile"
Is it not possible or am I missing something?
It is still (Q1 2020) not possible, but the next VSCode 1.42 will name its Untitled editors differently.
Untitled editors in VS Code are text buffers that have not yet been saved to disk.
You can leave them open for as long as you like and all text content is stored and restored between restarts.
Untitled editors were given generic names such as Untitled-1 and counting upwards.
In this release, untitled editors will use the content of the first line of the document for the editor title, and include the generic name as part of the description:
Note: If the first line is empty or does not contain any words, the title will fall back to Untitled_* as before.
So while you cannot set the title yourself (still readonly fileName), technically... changing the first line of that file would be enough to change the title of said "Untitled" editor.
With VSCode 1.43 (Q1 2020), a new setting workbench.editor.untitled.labelFormat allows to control whether untitled editors should use the contents as title or not.
Possible values are content or name.
Configure 'workbench.editor.untitled.labelFormat': 'name' to get the previous behavior back where untitled editors would have a short title, such as Untitled-1.
It's not possible - if you check out the source code for the API definition in vscode.d.ts, you'll see that fileName is declared as readonly:
export interface TextDocument {
// ...
readonly fileName: string;
// ...
}
Unfortunately, it seems that the readonly attribute isn't reflected in the API docs on the website.
This mainly happens if we create a new file in the OPEN EDITORS section, thus they appear as unsaved. To prevent this, create a folder for storing your files, and then in that folder, create your new file then it will show options to name it, also you can add a file type extension like .cpp.
TIP: vsc-rename-files extension to rename your files.

Automatic EOL conversion in Eclipse

Need to keep EOL format consistent in all resources under Eclipse workspace.
I know about Eclipse preference that sets new line style for newly created files, but I would like to have automatic conversion for already existing files. Is there some settings/plugins?
I want just setup once and be sure that all line endings are in the same format.
In addition to the Window > Preferences > General > Workspace setting for new files that you already know about, there is a File > Convert Line Delimiters To option. I don't know of any existing plugin/tool that will do this automatically when you save, but you could certainly write one or make converting the line ending part of your process.
To make it easier on yourself, you can bind keyboard shortcuts to the conversion commands by going to Window > Preferences > General > Keys and filtering using "delimiter":
In Eclipse, to convert the line endings for existing files:
Go to the file browser view, and click on the project/folder/file that you wish to convert.
From the menu bar, select File > Convert Line Delimiters To > Windows / Unix / MacOS 9.
You can Search your resources with the Search-Dialog and go to the tab File Search. There you can enter a Regular expression. Enter \r\n or whatever line ending you want to change.
Then hit the Replace .. Button instead of Search.
I want just setup once and be sure that all line endings are in the same format.
... ok, my answer does not consider this.
You might get usefull results with Eclipse save actions: If the eclipse formatter also converts the EOL style, you could use it to modify EOL style only for the files you are modifying.
Unfortunately I don't have eclipse here, so I can't test if this actually works. Worth a try, however.