Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I navigate lines of files with the keyboard quicker in IntelliJ?

Is there a keyboard shortcut or how can I set up a keyboard shortcut in IntelliJ to either:

  1. Go up/down several lines at a time (e.g. 5 or 10)
  2. Jump up/down a method in a class
  3. Go into a method hierarchy and then scroll up and down a method list

Or are their better ways to quickly navigate through code files with the keyboard?

like image 630
TTransmit Avatar asked Dec 24 '22 01:12

TTransmit


1 Answers

IntelliJ is incredibly flexible with so many shortcuts it's hard to remember them all. I didn't find a current builtin solution for your first shortcut request: "1. Go up/down several lines at a time (e.g. 5 or 10)"

However, a macro can be created and mapped to a keyboard shortcut. Follow these steps:

  1. First open a source file to edit.
  2. From the menu, select Edit -> Macros -> Start Macro Recording.
  3. Click the source file and then press Down five times.
  4. From the menu, select Edit -> Macros -> Stop Macro Recording and name your macro, I used "D5".
  5. From the main menu, select File -> Settings -> Keymap
  6. Within the key mappings, scroll down and find the Main Menu.
  7. Expand the Main Menu, then expand Edit, and then expand Macros.
  8. Locate the newly created "D5" macro and double click it. Key Mappings

  9. Add your desired keyboard mapping sequence. Be careful to find a shortcut not already in use. I went with Alt+Shift+5 Alt Shift 5

  10. Save your changes and you are ready to use your macro!

"2. Jump up/down a method in a class"

To navigate or jump to the next method use Alt+Down (on OSX, Ctrl+Down), previous method Alt+Up (on OSX, Ctrl+Up - This is overridden on Mac by Mission Control and fixed by going to System Preferences > Keyboard > Shortcuts > Mission Control.)


"3. Go into a method hierarchy and then scroll up and down a method list"

To open the "Hierarchy Callers" Panel, while the cursor is on a method, press Crtl+Alt+h

Next select one of the "callers" or methods within the list to navigate to the call.

To navigate to the previous or next caller, press Crtl+Alt+Up or Crtl+Alt+Down

To show a list of methods in a class and navigate to a method, Crtl+F12 on Windows or +F12 on OS X


Other navigation shortcut I find useful:

To navigate to the beginning or end of a bracketed statement: Ctrl+[ and Ctrl+]

There many other shortcuts for navigation, selections and code edits. To learn more open the Keymap settings and explore. Keymap

Page Up and Page Down will scroll to show lines above or below the current visible code.

like image 198
Heather92065 Avatar answered Jan 16 '23 23:01

Heather92065