IntelliJ Idea - Tips, Tricks and Shortcuts


This post is about helpful tips and tricks of Intellij idea which is the most popular IDE. This post will be updated continuosly with tips and tricks. It's a kind of never ending post. :)
Please post your tips, tricks and useful information about intellij in the comment box of this post so that i can update this article.

Shortcuts


  • ctrl + g    To go to particular line in a file
  • ctrl + n    To Open a java file
  • ctrl + shift + n  To open any kind of file
  • ctrl + space    Tye any characters and press the combo to get suggestions from IDE
  • Alt + Up, Alt + Down  -> You can easily move between methods in the editor.
  • Ctrl + Shift + V -> A dialog will be opened where you can chose and insert recent clipboard content.
  • Alt + F8 -> It evaluates an expression in debug mode when we choose text and do Alt + F8
  • Ctrl+Alt+Shift+N - To open a method or field in the editor quickly.
  • Ctrl+Shift+Enter - It auto-completes if, do-while, try/catch, return into a correct syntax structure.
  • ALT+Shift+F10 - To access Run/Debug dropdown without using mouse
  • Alt+Insert - It generates Getters and Setters of any field.
  • Ctrl+Alt+B - To navigate to the implementation(s) of an abstract method, position the caret at its usage or its name in the declaration.
  • Ctrl+Shift+J shortcut joins two lines into one and removes unnecessary space to match your code style.
  • Ctrl+Alt+Shift+N - Open any particular method or field in the editor and start typing its name.
  • Choose symbol from the drop-down list that appears.
  • Alt+Shift+C - To quickly review your recent changes to the project.
  • Use Basic Completion (Ctrl+Space) within HTML, CSS and other files, for completing image file names.
  • Use Ctrl+Shift+Enter to complete a current statement such as if, do-while, try-catch, return (or a method call) into a syntactically correct construct (e.g. add curly braces).
  • By pressing Alt+Shift+F10 you can access the Run/Debug dropdown on the main toolbar, without the need to use your mouse.
  • You can easily make column selection by dragging your mouse pointer while keeping the Alt key pressed.
  • If nothing is selected in the editor, and you press Ctrl+C, then the whole line at caret is copied to the clipboard.
  • Keep your source code typo-free with the help of the built-in Spellchecker.
  • All texts, including comments, textual strings and literals, are inspected against the pre-defined dictionaries. All typos are highlighted, which leaves you with the task of choosing the correct word, accepting the current spelling, or disabling inspection.
  • Use Alt+Enter to see the list of available actions.
  • If you lack words in the pre-defined dictionaries, you can create your own ones. A custom dictionary is a mere textual file with a .dic extension, with each word starting on a new line. All you have to do is to point to the directories where your dictionaries are stored, in the Spelling of the Settings dialog.
  • There are two ways of closing all tabs in the editor, except the current one:  First, right-click the editor tab, and choose Close Others on the context menu.  Second, keeping the Alt key pressed, click   on the editor tab.
  • To open any class or file in the editor at the desired line, press Ctrl+Shift+N (Navigate | File), start typing the name, and choose the one from the suggestion list. Then type the colon (:) and a line number. The selected file will open with the caret at the specified line.
  • To compare two directories, select one or both of them in the Project view and press Ctrl+D.
  • To compare two jar files, select one or both of them in the Project view and press Ctrl+D.
  • If you need more workspace, you can hide the tool windows bars: click   in the lower left corner. If necessary, you can show the tool window buttons just for a moment. To do that, press the key Alt (for Windows/*nix) or Command (for Mac) twice and keep it down. While the key is pressed, the tool window buttons are visible.
  • To view which line separators style is used in the current file, look at the Status Bar. To change the current line ending style, just click the spinner.
  • You don't need to leave IntelliJ IDEA to work with your favorite shell. Just click the Terminal tool window button, and enjoy using the embedded local terminal.
  • IntelliJ IDEA allows you to search through the classes, files, tool windows, actions, settings, and symbols of your project by double pressing the Shift key.
  • To select multiple fragments in the "column mode", keep Control+Alt+Shift(on Windows and Linux) or Cmd+Alt+Shift(on MAC), and drag your mouse cursor

  • -When using Code Completion, you can accept the currently highlighted selection in the popup list with the period character (.), comma (,), semicolon (;), space and other characters.
  • The selected name is automatically entered in the editor followed by the entered character.

  • - Use Basic Completion (Ctrl+Space) for completing words in text and comments in files of many       different types. All the words from the current file that start with the typed prefix will appear in the   lookup list.

  • -To quickly evaluate the value of any expression while debugging the program, hold Alt and click     the  expression to see its value and calculate it, call a method, etc.

  • - Right-clicking on a breakpoint marker (on the bar to the left from the text) invokes the speedmenu     where you can quickly enable/disable the breakpoint or adjust its properties.

  • - To quickly evaluate the value of an expression while debugging, hold Alt and click on expression     to  see its value or call a method etc.

  • - To learn the usage of each item in main menu, its short description is shown in the status bar at the   bottom left side of the application frame. Very useful tip for beginners.

  • - To quickly open eclipse project, from File -> Open dialog, select .project or .classpath file. The   corresponding Eclipse project is imported with default settings without launching the wizard.

  • -To help you learn the purpose of each item in the main menu, its short description is shown in the status bar at the bottom of the application frame when you position the mouse pointer over this item.
  • If you don't want to commit some of your changes to the repository, you can set them aside for a while, by moving to a separate changelist, or by putting them to a shelf. Select such file in the Local tab of the Changes tool window, and on the context menu choose Move to Another Changelist, or Shelve Changes.
  • You can quickly open an Eclipse project by selecting a .classpath or .project file in the File | Open dialog. The corresponding Eclipse project is imported with default settings, without launching the wizard.


------ to be continued

How to increase heap size in intellij idea


Go to Edit -> Custom VM options. If you are doing it for the first time, it gives a pop-up with two buttons. Just click on Create button and the file idea64exe.vmoptions file will be opened.
Change the value of xmx to increase the heap size of JVM. Save the file and restart the IDE.

Ex:

# custom IntelliJ IDEA VM options

-Xms128m
-Xmx4096m
-XX:ReservedCodeCacheSize=240m
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
-ea
-Dsun.io.useCanonCaches=false
-Djava.net.preferIPv4Stack=true
-XX:+HeapDumpOnOutOfMemoryError
-XX:-OmitStackTraceInFastThrow

Tip to improve the IntelliJ IDEA performance


If you notice that IntelliJ IDEA works slowly, consider the possibility to reduce the number of 
folders under antivirus protection. Each antivirus check in your project consumes resources. 
You can significantly improve the performance, if you exclude certain folders from the antivirus 
protection.

How to view the memory indicator in intellij

We can always view the memory indicator in the intellij. It means that how much heapsize is being used in proportion to the actual heap size alloted. Inorder to view that, check the option called 'show memory indicator' under Settings. See below pictures.

The below picture shows the memory usage in IDE






This picture shows how to set the option inorder to view the memory usage as in above picture.


Configure shorten command line in intellij

When we run JUnit tests we get "Command line too long..". To resolve this error go to Run/Debug Configurations -> Select JUnit -> Shorten command line -> Choose either Jar manifest or Classpath file from dropdown.




Comments

Post a Comment

Popular posts from this blog

Bash - Execute Pl/Sql script from Shell script

How to get client Ip Address using Java HttpServletRequest

How to install Portable JDK in Windows without Admin rights