Relative Actions is a plugin for IntelliJ-based IDEs to perform actions (move, copy, cut, delete, select and comment) relative to your current line. It behaves similarly to Vim but without needing to deal with Vim's modes.
- Move the caret up/down by N lines
- Move the caret to the beginning/end of a line
- Copy, cut, delete, select or comment:
- N lines above/below the current line
- A range of lines relative to the current line (e.g., comment lines 5 through 10 above the current line)
- A range of lines in both directions relative to the current line (e.g., comment 5 lines above and 10 lines below the current line)
Relative Actions can be installed directly from the IDE via
Settings > Plugins (see instructions).
Tip
To get the best experience, enable relative or hybrid line numbers in the gutter:
- Go to
Settings > Editor > General > Appearance - Set Show line numbers to
RelativeorHybrid
Press the keyboard shortcut to activate Relative Actions (Opt + K on macOS or Alt + K on Windows/Linux). The caret will change color to indicate that Relative Actions is active.
You can now perform a command relative to your current line. Commands follow a simple pattern: you specify what to do, how many lines, and in which direction. For example:
- Move only: Just specify a line number and direction (e.g.,
5lto move 5 lines up). - Move to the beginning/end of a line: Also specify a position (e.g.,
3elto move 3 lines up and to the end of the line). - Perform an action: Specify a line number, action and direction (e.g.,
3clto comment 3 lines up). - Work with ranges: Use a comma to specify a range of lines (e.g.,
2,5dkto delete lines 2 through 5 below the current line).
More examples:
6k: Move 6 lines down3dk: Delete 3 lines down10,5slSelect lines 5 through 10 above the current line5,ck: Comment only the 5th line below the current line3,5xb: Cut 3 lines above and 5 below the current line
Note
You can customize the activation shortcut under Settings > Keymap by searching for Relative Actions.
The last character in the action must always be the direction (k, l, or b), while all other characters can be
used in any order. For example, 3ck is equivalent to c3k.
The order of the numbers in a range doesn't matter. For example, 5,2ck is equivalent to 2,5ck.
To perform an action only on one line that's not the current line, e.g., to comment the third line above the current
line, you can use 3,cl, which is a shortcut for 3,3cl.
The following table shows all available keys you can use to build commands:
| Key | Operation |
|---|---|
k |
Direction: Down |
l |
Direction: Up |
b |
Direction: Bidirectional (only applicable with an action) |
w |
Position: Beginning of line (only applicable with move) |
e |
Position: End of line (only applicable with move) |
y |
Action: Copy |
x |
Action: Cut |
d |
Action: Delete |
s |
Action: Select |
c |
Action: Comment |
Note
All key bindings can be customized under Settings > Tools > Relative Actions.
Like Vim, Relative Actions has a steep—though arguably gentler—learning curve, so don't be discouraged if you don't get it right away. The more you use it, the more natural it will feel.