= Hints and Tips

:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


== Keyboard Cheat Sheets

You can download 1-page PDFs cheat sheets for IntelliJ's keyboard shortcuts:
* for link:https://www.jetbrains.com/idea/docs/IntelliJIDEA_ReferenceCard.pdf[Windows]
* for link:https://www.jetbrains.com/idea/docs/IntelliJIDEA_ReferenceCard_Mac.pdf[MacOS]

Probably the most important shortcut on them is for `Find Action`:
- `ctrl-shift-A` on Windows
- `cmd-shift-A` on MacOS.

This will let you search for any action just by typing its name.

== Switch between Tools & Editors

The Tool Windows are the views around the editor (to left, bottom and right).
It's possible to move these around to your preferred locations.

* Use `alt-1` through `alt-9` (or `cmd-1` through `alt-9`) to select the tool windows
** Press it twice and the tool window will hide itself; so can use to toggle
* If in the _Project Window_ (say) and hit enter on a file, then it will be shown in the editor, but (conveniently) the focus remains in the tool window.
To switch to the editor, just press `Esc`.
** If in the _Terminal Window_, you'll need to press `Shift-Esc`.
* If on the editor and want to locate the file in (say) the _Project Window_, use `alt-F1`.
* To change the size of any tool window, use `ctrl-shift-arrow`

Using these shortcuts you can easily toggle between the tool windows and the editor, without using the mouse.
Peachy!

== Navigating Around

For all of the following, you don't need to type every letter, typing "ab" will actually search for ".*a.*b.*".

* to open classes or files or methods that you know the name of:
** `ctrl-N` to open class
** `ctrl-shift-N` to open a file
** (bit fiddly this) `ctrl-shift-alt-N` to search for any symbol.
* open up dialog of recent files: `ctrl-E`
* search for any file: `shift-shift`

Navigating around:

* find callers of a method (the call hierarchy): `ctrl-alt-H`
* find subclasses or overrides: `ctrl-alt-B`
* find superclasses/interface/declaration: `ctrl-B`

Viewing the structure (ie outline) of a class
* `ctrl-F12` will pop-up a dialog showing all members
** hit `ctrl-F12` again to also see inherited members

== Editing

* Extend selection using `ctrl-W`
** and contract it down again using `ctrl-shift-W`
* to duplicate a line, it's `ctrl-D`
** if you have some text selected (or even some lines), it'll actually duplicate the entire selection
* to delete a line, it's `ctrl-X`
* to move a line up or down: `shift-alt-up` and `shift-alt-down`
** if you have selected several lines, it'll move them all togethe
* `ctrl-shift-J` can be handy for joining lines together
** just hit enter to split them apart (even in string quotes; IntelliJ will "do the right thing")

== Intentions and Code Completion

Massively useful is the "Intentions" popup; IntelliJ tries to guess what you might want to do.
You can activate this using`alt-enter`, whenever you see a lightbulb/tooltip in the margin of the current line.

Code completion usually happens whenever you type '.'.
You can also use `ctrl-space` to bring these up.

In certain circumstances (eg in methods0) you can also type `ctrl-shift-space` to get a smart list of methods etc that you might want to call.
Can be useful.

Last, when invoking a method, use `ctrl-P` to see the parameter types.

== Refactoring

Loads of good stuff on the `Refactor` menu; most used are:

* Rename (`shift-F6`)
* Extract
** method: `ctrl-alt-M`
** variable: `ctrl-alt-V`
* Inline method/variable: `ctrl-alt-N`
* Change signature

If you can't remember all those shortcuts, just use `ctrl-shift-alt-T` (might want to rebind that to something else!) and get a context-sensitive list of refactorings available for the currently selected object

== Troubleshooting

When a Maven module is imported, IntelliJ generates its own project files (suffix `.ipr`), and the application is actually built from that.

Occasionally these don't keep in sync (even if auto-import of Maven modules has been enabled).

To fix the issue, try:

* reimport module
* rebuild selected modules/entire project
* remove and then re-add the project
* restart, invalidating caches
* hit StackOverflow (!)

One thing worth knowing; IntelliJ actively scans the filesystem all the time.
It's therefore (almost always) fine to build the app from the Maven command line; IntelliJ will detect the changes and keep in sync.
If you want to force that, use `File > Synchronize`, `ctrl-alt-Y`.


// include::partial$UNUSED/faster-turnaround-times.adoc[]
