IntelliJ - not asking if I want to save a file - intellij-idea

I'm new to the IntelliJ IDE. In the past I was working with Visual Studio or Eclipse.
In those IDEs there was an asterisk * above the name of the file which has been modified.
But in IntelliJ with the default configuration I can't see if the file is modified. What's more the file is saved automatically when I change focus to another window.
I've found some options under Settings -> IDE Settings -> General -> Synchronization:
Synchronize files on frame activation
Save files on frame deactivation
Save files automatically if application is idle for...
After unchecking all that options the file is not saved automatically every time I change focus to another window, which is good. But still I can't:
see if the file is modified (no asterisk)
decide if the file should be saved when I'm closing it (IDE doesn't ask for that)
And when I'm closing IntelliJ file which has been modified is saved without even noticing.
Do you know what can I do to change how IntelliJ behaves?

After unchecking mentioned options go to:
Settings/Editor(IDE Settings)/Editor Tabs:
Check "Mark modified tabs with asterisk"
On 2019.3 Ultimate it's under:
Settings/Editor/General/Editor Tabs:
Mark modified (*)

The exact Save feature like eclipse is not available in IntelliJ.
Because IntelliJ IDEA has the ability to change so many files
simultaneously in large refactoring actions, and change them without
ever opening them, single file saves don't make very much sense. In
recognition of this, IntelliJ IDEA reserves the right to save any of
your files literally whenever it wishes. It's actually quite nice to
never have to worry about your file's save statuses, once you get used
to it.
"What if I don't like some changes I made, and want to roll them
back?", I hear you say. Well, for that IntelliJ IDEA includes this
amazing feature called the Local History. Every time it saves your
files, IntelliJ IDEA actually saves a diff of your file from it's
previous state, and saves that as well. You can see the entire edit
history of your files (going back some number of days), see the
changes you've made, and roll back any change. It rules triumphantly,
and more than makes up for the temporary disorientation caused by lack
of single-file save.
https://intellij-support.jetbrains.com/hc/en-us/community/posts/206336279/comments/207351939

To show an asterisk when a file is modified: open Settings (CTRL+ALT+S), switch to Editor > General > Editor Tabs and select the Mark modified tab with asterisk checkbox.
To remove autosave, uncheck: Appearance & Behavior > System Settings > Save files on frame deactivation

Related

IntelliJ Show Diff Includes Unversioned Files

After upgrading to IntelliJ IDEA 2021.2.2 Ultimate Edition, I've noticed now that when I go to the Commit pane and select Show Diff on a file in the Default Changelist, that it includes the Unversioned Files in the set of files for the diff comparison.
That is, say I only change one line of code in pom.xml but I also have some un-versioned file, let's say called temp.sql. If I open the Show Diff tool by select Show Diff from pom.xml in the Default Changelist, then the Compare to Next File button is still enabled. Clicking it takes me to temp.sql`, though I have no desire to look at it since I don't even have it in source control.
For example, here I have a Default Changelist with a change to one file in source control, pom.xml. And I have an un-versioned file called temp.sql.
When I select Show Diff on a file in the Default Changlist, it should, in my opinion, and in my previous version of IntelliJ, only show you...the Default Changelist, which is pom.xml. Instead it is giving me pom.xml and temp.sql.
Is this a new feature? It seems like a bug to me. I can't seem to find any documentation for it. I can't find any way to turn it off.
I see there is a "Show unversioned files" check box in the Version Control > Commit section of Preferences, but clicking it doesn't seem to change anything.
If I choose Show Diff on the Default Changelist object, rather than on a file in the Default Changelist, that it restricts navigation to the files in the change list as I want. It's only if I select Show Diff from a file in the Default Changelist that includes all files in all change lists, including un-versioned files.
Ruslan Kuleshov made a comment that this seems like a known issue, https://youtrack.jetbrains.com/issue/IDEA-237528.
New commit tool: don't jump to other changelist's changes
I always review all changes on the current changelist before commit. I focus the diff preview and use F7 to jump through all changes on all files. Previously, when I reached the last file F7 stopped jumping to other files. But after enabling the new tool, when I press F7 on the last changed file on the current changelist, it jumps to the first change on the next changelist. That's a problem since I can begin reviewing changes which are not intended for commiting right now, loosing time, confusing me and even risking to mix files from different changesets.
I had failed to find that issue on https://youtrack.jetbrains.com because I hadn't yet tried having files in source control with changes in a non-default change list. I was only searching YouTrack for the fact that Show Diff now includes un-versioned files.
So, it seems that if you choose Show Diff from a file in a change list, then the diff comparison tool will now include all files in the set of files, regardless which change list they are in and regardless whether they are in source control yet.
I think that this is a bug and have voted for the issue. I encourage others to do so as well.

IntelliJ IDEA reload file from disk on type

I have used Emacs a lot, and in Emacs when you try to edit a file which has been modified on disk, it disallows it, prompts that the file has changed, and asks you what you want to do about it.
In IntelliJ, if a file has changed on disk, I can type forever. This just happened to me: I wrote a 20 line function, and tried to save. Then IntelliJ prompted that the file had changed. I had the option of overriding my changes with the data on disk, or to corrupt the whole file by keeping the current data. I wanted to just copy my function and reload, but I couldn't even do that because the popup had the focus. I there isn't even a button to cancel the save. I pressed Escape and prayed that my change would be overwritten. What a nightmare...
Is there any way to make IntelliJ prompt on the first character typed? I really don't want to synchronize the whole project every time I start to edit a file a switch git branch.
Preferences > Appearance & Behavior > System Settings
Under the heading 'Synchronization', enable the property 'Synchronize files on frame or editor tab activation'.

Intellij undo history size, not much?

I like to be able to undo basically several hours of work in a file. I am unsure how to configure this.
In IntelliJ settings, the clipboard settings I have tried with are 999 and 9999 and 99999 but it still too short on undos.
How can I increase this?
In Intellij settings the clipboard settings I have tried with are 999 and 9999 and 99999 but it still too short on undos.
I've failed to see what "clipboard settings" have to do with the "undo limit" (or with "undo" at all). Care to explain?
Local History is definitely the way to go here as it works across sessions, files, and whole folders -- you can undo very complex operations in one click (e.g. replace/refactor in multiple files).
In any case: if Local History is to complex or you are a hardcore person who prefers to hit Ctrl + Z quite a few times in a row instead of few clicks with Local History, you can increase undo limit (which is 100 steps by default). For that:
Open Registry (Help | Find Action... and type registry)
Find undo.documentUndoLimit entry and set your limit to a higher number (e.g. 1000).
P.S.
IDE restart may be required.
Actually, based on JetBrains Docs, for changing undo limit you should act just like below steps:
click Help on the top menu:
Click on Find Action:
Type Registry and open first result:
On the opened window file undo.documentUndoLimit and undo.globalUndoLimit and change it to number what you want.
HINT: After change you should close your JetBrains IDE and open it again.
The "Maximum number of contents to keep in clipboard" setting has nothing to do with undos.
In fact, there is no configurable "undo history size" setting in IntelliJ. See this support issue:
For rolling back complex code changes gone awry, a far better option is to use the local history.
Local History is available under the menu "VCS" -> "Local History" -> "Show History". The feature is explained as:
IntelliJ IDEA tracks any changes you make to your source files or any other file, as well as the changes that affect a directory’s content and structure. This feature will protect you from any accidental losses or modifications, even if made by other applications outside IntelliJ IDEA. Setting version labels is also available. Any time you can inspect the history of either a particular file or directory and rollback to any of its previous versions.

How to detect file changed by myself in IntelliJ IDEA

Is it possible in Intellij to mark edited file tabs with a star (*) so that I can see which files I have changed.
By default, Intellij automatically saves your edits every few seconds, and every time it looses focus. So, most of the time your files are not in a changed state, so no icon is needed. However, under Settings, IDE Settings, Editor, Editor Tabs, there is an option to Mark modified tabs with asterisk, which will enable the feature you want.

In Intellij IDEA how do I reload file content's from disk?

In vim I can type :e and reload a file's contents from disk overwriting any changes I've made. It's a nice way to reset in case I've gotten lost or just want to undo all my changes. This obviously doesn't take into account any kind of refactoring, I just want to nuke all changes to buffer. Not even closing and reopening a tab will work.
How do I do this with Intellij IDEA? I'm using Intellij IDEA Ultimate 13 and I've disabled any kind of auto save.
File > Synchronize (Ctrl+Alt+Y)
It will load the file from the file system. If you have unsaved changes, it will ask if you want to discard them.
⌥⌘Y - Synchronize for Mac users
What I do in a similar situation:
Simple - Ctrl+Z, Ctrl+Shift+Z many times to quickly navigate the editing history
VCS rollback - either for the whole file or for the area being edited (by clicking green areas on the left)
Local History. Well, yes, for you case it's granularity is not sufficient, so first might be an option
There is also an option to put a label into Local History if you need to rollback to a specific point in time.
For those who use autosave - it is being triggered when code editor loses focus. So doing Alt-Tab during long editing without compiling or running the code makes sense.
Open the file in another editor, make an insignificant change and save it. PHPStorm will ask you what to do because the file system and in memory copies of the file have diverged. Click "Load File System Changes".
Note, I was unable to use my undo history as it had become corrupt.
Since what I want isn't really possible I wrote an extension to do it for me:
https://github.com/btipling/DiskRead/
I'll add it to the Jetbrains plugin repository, it's called "DiskRead".
I wrote a blog post about how I created this if anyone is curious.