问题
Is there a keyboard shortcut or how can I set up a keyboard shortcut in IntelliJ to either:
- Go up/down several lines at a time (e.g. 5 or 10)
- Jump up/down a method in a class
- 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?
回答1:
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:
- First open a source file to edit.
- From the menu, select Edit -> Macros -> Start Macro Recording.
- Click the source file and then press Down five times.
- From the menu, select Edit -> Macros -> Stop Macro Recording and name your macro, I used "D5".
- From the main menu, select File -> Settings -> Keymap
- Within the key mappings, scroll down and find the Main Menu.
- Expand the Main Menu, then expand Edit, and then expand Macros.
Locate the newly created "D5" macro and double click it.
Add your desired keyboard mapping sequence. Be careful to find a shortcut not already in use. I went with Alt+Shift+5
- 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.
Page Up and Page Down will scroll to show lines above or below the current visible code.
来源:https://stackoverflow.com/questions/39686376/how-can-i-navigate-lines-of-files-with-the-keyboard-quicker-in-intellij