Vscode randomly remove code when using format on save - visual-studio-code

I am using format on save feature in vscode for a while. And sometimes when i save, which invoking format on save, vscode randomly remove function and other sentence. I dont have any formatting extension. Here is the image. I can just undo but im really afraid its not restore all the code.

It formats on save
Maybe you need to look into your components
for example: Toggle Format on Save

Related

Format only pasted code segment in VSCode, not entire document

Is there a way to do so? I find a lot of my time is taken up correcting indentation formatting in VSCode after pasting, because it seems to sometimes take the source indenting and apply it at the destination (so the entire pasted code block is at the wrong indent level) or worse, just mess up indents entirely (no idea what's going on here) and I need to manually fix every line.
Example use case, for single PHP files which contain PHP, HTML, and Javascript, I often only want the pasted Javascript block to format nicely. Turning on "paste on format" will format the entire document, often times making the PHP sections awkwardly arranged.
I know that VSCode has "format on paste" in settings, but this formats the entire document. How can I format only the pasted code? Is this even possible?
Thank you
I am not certain whether you're fine with this roundabout solution, but you can format selection with Ctrl+K Ctrl+F (see official vscode site for more detail). So rather than turning on format on paste you can paste and then reselect it and do the shortcut above.
If you're not satisfied with this method, you can try using a vscode extension that was given here under a somewhat similar copy and paste problem

VS Code JSON Format Reverts on File Change

I know you can format on demand, save etc. However, I want my JSON files to be formatted automatically when I open them.
I'm currently using Prettier for my default formatter; which works great when I force the formatting through ctrl+shift+p > format document or just pressing ctrl+s does it (because I have that enabled).
I forgot to mention that if I have the file open in the editor (no pending changes) and the file is updated from a source outside of the editor, the formatting resets.
How can I prevent the formatting from resetting after the file is updated?
Does anyone have this working and if so how?

eclipse reformat only edited lines

I am working with Java. If I hit Ctrl+Shift+F in Eclipse Helios, it will auto format the entire file instead of the lines I edited. This becomes a nightmare at the time of check in when someone else uses a different style on the same file. Is there a way to tell eclipse to only format the touched lines in a file.
Windows-Preferences-Java-Editor-Save Actions
Format only saved lines. However, if you hit Ctrl+shift+f i don't think there is a way that only edited lines will be saved.
If you select a range of lines in the editor then the format is done just on that range, if there is nothing selected the whole file is formatted.
You can change the formatting style used in Preferences / Java / Code Style / Formatter.
You can control formatting and other actions done when saving a file in the Jova / Editor / Save Actions preferences.
Look at the preferences page for the available Save Actions.

Is there a way to copy code from the Eclipse IDE without the rich-text formatting?

Recently every time I copy a block of code from Eclipse and paste the code into TextEdit or a online forum using the code tags, I get the code with the rich-text or html formatting, so I have to copy into a text editor remove the formatting copying and pasting again, In the past this was not a problem I used to copy from eclipse and paste the code without any formatting at all just as plain-text, I dont know if I turn on a property or what I did for this to happen, any ideas how to fix this?
There is an Eclipse bug filed for this that can be voted for:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=45969
It has been open for 10 years though!
There are applications out there that think they can handle rich text but can't. So for those it looks like we'll have to carry on with "Copy-Switch to Notepad-Paste-Select All-Copy-Switch to final app-Paste" for some time yet.
Note: the rich formatting from a SWT editor seems to have always been available (bug 64498).
You could use "Edit, Paste and Match Style" in TextEdit.
From the Edit menu, choose Paste and Match Style,
or use the keyboard shortcut, Shift Option Command V.
The pasted text will pick up all the formatting from the character to the left of the flashing insertion point. This technique works in Mail as well.

Why does file have to be saved prior to running?

In MATLAB, why does the file have to be saved prior to running ?
I often try quick snippets of code, which I could also easily run also on the Command Window line by line. So, why when I run them through the editor, I have to save them first ?
Can this behaviour be changed, maybe ?
You can use cell mode in the editor placing %% before your code. See also Cell menu in the editor. Once you create cells, you can run them one by one pressing Ctrl-Enter. You don't need to save the file. However you cannot use editor's debugging features (breakpoints, etc).
Video tutorial
my guess would be that when you run your program, the matlab interpreter run it from the disk and not from the IDE buffer. so if you don't save the file it wouldn't run the correct code.