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?
Related
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
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
while i do something changes in setting of vs code then File seems to be binary and cannot be opened as text error occurs and not able to do any changes in vs code also not working the setting changes.
How can I force PlantUML to refresh its preview, using code?
Longer Explanation
I have 2 editors open
Editor 1 contains a yml file.
Editor 2 contains a plantuml .wsd file
and a 3rd pane is showing the plantuml preview. (which is technically not an editor)
When I modify the yml file, it modifies a json model, and rewrites the .wsd file, and thus I get a new state diagram showing me the structure of my yml file in graph format.
The content of wsd is updating correctly when the yml changes. V1 created a new file each time, it saved fine I could see the content change, but the preview never updated.
Settings->PlantUML auto update is ticked.
In order to trigger the refresh I had to select the editor, and either modify or save.
So I re-wrote the code to select the editor 2 wsd contents, replace it in the existing file, and then save that file. Still the preview does not update.
I have also tried to fire the vscode command plantuml.preview, which is what the plantuml extension itself fires to display the preview, it fires and returns, but does not update the preview.
I have vscode.window.visibleTextEditors[ii], from which I can select the right editor, but I cannot find anything to set the focus. I've tried setting selections, and saving but still no refresh.
I am now trying to find the right vs code way to set the focus on the right editor and save it, then switch back to the left editor, mimicking pressing CMD-2, CMD-S, CMD-1, or manually selecting the editor and saving, which is the only way to update the preview.
I cannot find anything on how to set the editor focus, so perhaps I am going down the wrong path. Can anyone suggest how this could be done?
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.