⚙️ Get into IdeaVim configuration, from basic to advanced
The IdeaVim is a Vim emulation plugin for IntelliJ Platform-based IDEs. It has a lot of supported motions and operations and can help you to quickly edit code and navigate through it.
Install IdeaVim by using the IDE's plugin manager (File -> Settings -> Plugins -> Search for IdeaVim -> Install IdeaVim).
Basic configuration
You can configure IdeaVim with the ~/.ideavimrc
File. Which
is quiet mighty and very useful. It is similar to a .vimrc
file and supports some of the default vimrc settings and commands.
Set Commands
For basic settings. Here some useful examples:
Disable select mode for refactoring
Usually IntelliJ will go in the select mode
, when
refactoring a variable or method name. This is only useful, if the
whole name should be changed. So the normal mode
, is
better for me:
set idearefactormode=keep
Enable IdeaJoin
For the great IntelliJ join functions. Keymap: J
(Shift+j).
set ideajoin
Plugins
Some Plugins are already build in IdeaVim, and must not be installed
manually. You enable it via the Plug
command .
Activate surround Plugin
which emulates the the Vim
Surround plugin. Normal
mode: ys
, visual mode: S
Plug 'tpope/vim-surround'
Activate commentary Plugin
which emulates the the Vim
Commentary plugin. Keymap:
gc
Plug 'tpope/vim-commentary'
Keymaps
They work the same like in Vim. map
is the keyword.
noremap
for non non-recursive mappings. And
nnoremap
for normal mode, vnoremap
for visual
mode, etc.
Small examples:
Yank to the last character of the Line
Y
(Shift + y)
nnoremap Y yg_
Jump to the class definition
"(gh = go to header)
nmap gh gg<Action>(MethodDown)mxz<CR>5<C-y>`x
" gg = go to beginning
" mx = sets a mark, so we can jump back
" z<CR> = Scrolls to te Top
" 5<C-y> = scrolls the window 5 lines
" `x = jumps back to our mark
IntelliJ Actions
The interesting part. You can execute every action, you might find in
IntelliJ. For example, refactor a variable
,
fetch changes
, run tests
, etc. With this, you
might configure IntelliJ to behave like
Spacemacs or Doom
Emacs. (They use
Space
as leader key and enable you to execute regular
commands with it. For example SPC-g-F
for git fetch)
With the command <Action>
(nearly) every possible action can be
triggered.
Examples
Show Commit Tool Window
nmap <Leader>gg <Action>(ActivateCommitToolWindow)
Set bookmark and show bookmarks
nnoremap <leader>bm <action>(ToggleBookmark)
nnoremap <leader><enter> <action>(ShowBookmarks)
Run Main Method, Test or Class
nnoremap <Leader>rr <action>(RunClass)
Find Actions
To find an overview about all actions or search for them type:
:actionlist
Find via name/description
:actionlist commit
Find via Keymap
:actionlist <C-K>
"Track action Ids" is very helpful. When performing an action via mouse click and/or keyboard, a popup shows the last used action id. You find this "IdeaVim: track action Ids" in the ActionsMenu (double click shift)
Advanced IdeaVim configuration
In this chapter I will explain which Plugins are helpful and how to
extend the .ideavimrc
config with Intellimacs and my own
config. This will enable some nice key chords to execute most of your
IntelliJ actions with it. For example, when you press space (SPC),
"g", "b", you can change your Git Branch. Most of the commands start
with your "Leader" Key, which will be the space bar. Then it will
continue with a group, like "g = Git" and then your final action "b =
switch (b)ranch". Of course there are shorter and longer ones, too.
Here some more examples:
Key binding | Description |
SPC g l | (g)it (l)og |
SPC f o | (F)ile (o)pen |
SPC r r | (r)un method |
SPC r s | (r)un (s)elected method |
SPC , | show last used files |
Some commands doesn't start with the leader key, like
Some commands doesn\'t start with the leader key, like
Key binding | Description |
g t t | (g)o to (t)ests |
g d | (g)o to (d)efinition |
g i | (g)o to (i)mplementation |
g s | (g)o to (s)uper class |
Some are longer and start with "SPC m" or ",". Also named your "local leader" key.
Key binding | Description |
, d d | start debug mode |
, d s | select method for debug mode |
, r i n | refactor and inline variable/method |
, r e v | refactor and extract as variable |
, r e p | refactor and extract as parameter |
, r e c | refactor and extract as constant |
In my opintion, they are much easier to remember, then usual hotkeys. But of course, you can mix them as you want.
Plugins
There are a lot of additional IdeaVim Plugins, here my favorites
Commentary
Commend out your code. Commands: gcc
, gc
+
motion Enable with:
Plug 'tpope/vim-commentary'
Surround
Surround your text with brackets etc.. Commands: ys
+
motion + sign, (insert mode) S
+ sign Enable with:
Plug 'tpope/vim-surround'
Intellimacs
This project mimics Spacemacs key bindings. This is a good starting point for your configuration. It has a ton of useful keymaps. Like:
Key binding | Description |
SPC g c | Git clone |
SPC g f l | Show current file log |
SPC g b | Git branches (checkout) |
SPC g G | Version control tool window |
SPC g g | Select a version control operation |
SPC g p | Push |
SPC g S | Show shelf |
and much more..
Clone it via:
git clone https://github.com/MarcoIeni/intellimacs ~/.intellimacs
And add those lines to your .ideavimrc
file
source ~/.intellimacs/spacemacs.vim
source ~/.intellimacs/extra.vim
source ~/.intellimacs/major.vim
source ~/.intellimacs/hybrid.vim
Check the Github page, for a more detailed description
Early Access Program
You might enable EAP (Early Access Program), to get new features more quickly. Go to "Vim Actions" and select EAP, to enable it.
My IdeaVim configuration
My whole configuration with (some) comments you can find here: IntelliJ's IdeaVim Configuration. The plain config: .ideavimrc.
Further readings and link collections
This is a list of the links above and some more further readings from other blog posts:
- IdeaVim Github Page
- List of Supported Set Commands
- List of Supported motions and operations
- IdeaVim Changelog
- Intellimacs Further getting started guides:
- Getting started with Ideavim
- Customizing IdeaVim