Is there a way to open any file as text in VS Code? - visual-studio-code

VS Code is currently my favourite text editor, except for Jupyter notebooks, which are opened as interactive python environments (let's call this 'rendered').
By itself it is nice that this is possible, but not I can live with opening them in a browser if VS Code would not render them.
There used to be a setting to avoid this behaviour ("jupyter.useNotebookEditor": false) but currently my installation does not recognise this setting anymore.
Since there are more file types that can be opened as text/source, or rendered form (e.g. html, md, svg, uncompressed pdf, etc.) and both forms can be usefull, I would be very excited to learn how to switch between rendered and source, preferably without switching global settings.
Is there a way to do this? I would hope for:
a mechanism that does not depend on (or can be overwritten by) the current jupyter extension
a mechanism that works for any file type (nice-to-have)

Are you just looking for a way to view/edit the raw json?
You can right click the file in the Explorer -> open with... -> text editor.
Or use "Reopen editor with text editor" from the command Palette (ctrl+shift+p)

Related

How to create a modal for a VSCode extension?

I'm trying to make an extension for VSCode to Find text in File (Like in Notepad++).
Is there an API for using a modal in a VSCode extension? or at least extend the Command Palette?
VS Code (1.34) has no concept modal UI. Extensions can only show basic dialog messages modally using the showMessage apis.
Messages can show message text and a set of buttons. By default VS Code will render messages in its UI. The MessageOptions.modal option makes VS Code render the message using system UI instead.
Try positing a more specific question about what you are trying to accomplish. VS Code's extension model is different from other editors, so if you are trying to replicate functionality from another editor like Notepad++ you may need to rethink the user experience.
I believe what you are looking for is an input box. It will show a UI where you can input text. From there you can grab the text of a document and parse it for entered text. For completeness, VS Code does this with ctrl + f or cmd + f depending on OS. Add the shift key to search the whole project.
As mentioned above there are the limited built-in inputs and message box (which can also be used to display choice buttons).
You can also have a look at WebView these can be used to display a side-bar view (like the EXPLORER) or a full document. They are made up from HTML and plain old JavaScript. You will have to pass simple string messages between your HTML/JS view and vscode itself.
https://code.visualstudio.com/api/extension-guides/webview
https://github.com/Microsoft/vscode-extension-samples/tree/main/tree-view-sample
A large 'document' view example vscode extension is call 'nearest-icons'
https://github.com/noGreg/nearest-icons

VS Code. How to open JSON settings with defaults

When I'm opening settings using Preferences: Open Settings (JSON) I'm getting screen like this:
But in VSCode videos/tutorials I see people somehow have splitted window, with default settings on the left and user/workspace setting on the right:
How I can enable it?
===========================
EDIT:
I found "workbench.settings.openDefaultSettings" option and set it to true, but still my UI is different from desired on screenshot above ( I don't see search box for searching settings, also I don't see the message Place your settings in the right ... to override):
As mentioned #Juraj Kocan in comments, it happens after last VS Code updates.
This is Github issue related to this new "feature"
This one helped me:
"workbench.settings.useSplitJSON": true,
"workbench.settings.editor": "json",
How to Get to the JSON settings in Newer Versions of VS Code
In the latest versions of VS Code, you can convert back to the split JSON settings editor by changing the following settings in the (now standard) UI settings editor:
Workbench > Settings: Editor
Change from UI to json
Workbench > Settings: Use Split JSON
Checkmark to enable the option
after making this change, VS Code will open its settings as a JSON file, like in older versions of the application, rather than in the new UI. This allows you to make the changes that other answers provide, directly in the JSON (if you can find the right place and file to make them in..)
NOTE: Whether or not you actually want to use the JSON settings is a different question. Most of the time, the settings search function allows finding the same settings in the new UI. Sometimes it is difficult to get search to work though, especially if the settings are worded differently in the new UI style. There may also be cases where extensions haven't been updated to accommodate the new UI setting style, and so there is no option but to enter the JSON directly.
Not sure what do you mean by "Default".
steps to open setting by keyboard are:
press Ctrl+p (an input command line would appear at the top.)
press >
A List will appear like that in image. (search preference for all vs code settings)

Change VSCode Default Language for new files?

Is there a way in Visual Studio Code to change the default language that is used for new files?
By default if you open a new file, it's set for "Plain Text", I want this to be "HTML" instead.
I am often copy pasting HTML into VSC, editing a bit, then copying it back to a CMS I am using (the CMS editor is horrible). I don't want to save the code on my computer at all, just edit it a bit with HTML syntax highlighting, but I want that to be the default.
You can now set the default language at either the user or workspace settings level using files.defaultLanguage:
"files.defaultLanguage": "html"
This can be done as a one off by changing the language mode:
F1 to launch command palette
Type lang, enter
Type html, enter
Now you can do this change. Check out
"files.defaultLanguage" in settings.
With v1.42 you can either set
"files.defaultLanguage": "${activeEditorLanguage}"
and when you open a new untitled file with an html file as the last active file, the new file will automatically be assigned a languageMode of HTML.
Alternatively, pasting any html code into a new untitled file from a vscode editor will automatically be detected and the languageMode set to HTML. Unless you have specifically set
"files.defaultLanguage": "plaintext"
then the languageMode will not be automatically detected as of v1.43.
Also see https://stackoverflow.com/a/68596936/836330 for a preview language detection feature in vscode 1.59.
A slightly quicker way to accomplish what Daniel had answered:
Press Ctrl+K, then M
Type html, then press Enter
I had a similar issue with VS Code. I wanted to default to Python when opening new files.
Solution: Click on File > Preferences > Settings. In the search area, Type: "files.defaultLanguage". Then fill in the language of your choice.
Perhaps you could create a scratch file with the .html extension? Open that when you need to do some copy/paste editing.

Disable visual editors in MyEclipse

What is the best way to disable all visual editors in MyEclipse?
Every time I open an HTML file, it spends a few seconds to render the HTML file in a wysiwyg editor and fails at it.
Every time I open a properties files, it opens it in a excel-like table that completely ignores the comments in the properties files.
The first thing I do is to hide the visual panel to revert to the source code.
I never use a wysiwyg editor or any design wizard. But I can only change file associations one type at a time. For HTML I have to change the assotiation for .html, .htm and .xhtml. Same for the various .xml files.
Isn't there a way to remove or disable all visual editors for good, so that MyEclipse doesn't spend time and memory on it? Maybe even uninstall them?
Right clic on File > Open With > text editor
After doing that for a file, eclipse keep this as default for the file
or in preferences, in General > Editors > File Associations set for every extension the text editor associate to it (but like you said, you have to do it for every extension, but it doesn't take so much time to do it and once you've set it, it's remembered)

Eclipse file associations for extensions with multiple periods

I have several Mako templates in my project that are named things like header.html.tmpl and settings.py.tmpl. I would like to add file associations to Eclipse to open these with the appropriate editors. For example, I would like header.html.tmpl to be opened in the HTML editor, settings.py.tmpl to be opened in the Python editor, etc. I go to Preferences->File Associations and I try adding *.py.tmpl to the list but after I click "Ok" nothing happens and the desired extension does not appear in the list. If I try instead using .py.tmpl I can add it to the list and add the Python editor to its associated editors but when I double-click a .py.tmpl file it doesn't use the correct editor.
Obviously it would probably work to just use -tmpl instead of .tmpl, but I'm wondering if anyone knows a way around this or can confirm that it's a bug/missing feature.
Its a bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=168573