Vim in IntelliJ IDEA
IdeaVim is a Vim engine for the IntelliJ IDEA editor. It supports the normal, insert, and visual modes, Command-line and Ex modes, Vim regexp and configuration, and other features.
In the Settings dialog (CtrlAlt0S) , select Plugins.
Find the IdeaVim plugin in the Marketplace and click Install.
Restart IntelliJ IDEA.
After you restart the IntelliJ IDEA, Vim is enabled and the editor starts operating in the Vim mode. To disable it, deselect Tools | Vim in the main menu.
Both Vim and IntelliJ IDEA are keyboard-centric. Your keymap in IntelliJ IDEA may conflict with Vim's key combinations. To resolve this, select the shortcuts you prefer for different actions.
Press CtrlAlt0S to open settings and then select Editor | Vim.
Find the shortcut and corresponding IDE action, and select how you want to handle it when you are using Vim:
Undefined: show a popup notification that suggests to either redefine the IDE shortcut or configure the handler in the settings.
IDE: perform the IDE action associated with this shortcut.
Vim: handle it as a Vim shortcut.
With Vim, the caret is a block when you are in the Normal mode:
To change to the Insert mode, press i, and the cursor will become a line:
In this mode you can type new code or change existing code. You can also enter other Vim modes: for example, press R for the Replace mode.
To return to the Normal mode, press Esc.
Vim is configured using a vimrc file. Similarly, the IdeaVim plugin uses an ideavimrc file with the same syntax.
In the status bar at the bottom of the IDE window, click the IdeaVim widget and select Create ~/.ideavimrc.
IntelliJ IDEA creates the file and opens it in the editor. You can use this widget later on to quickly access your ideavimrc file.
tip
You can find examples of the ideavimrc file in this GitHub discussion.
The configuration file will be created in one of the following locations depending on the operating system:
%HOMEPATH%\_ideavimrc
~/.ideavimrc
~/.ideavimrc
note
The location where IntelliJ IDEA looks for ideavimrc depends on the
user.home
JVM option, which is set to the user's home directory by default. For more information, refer to JVM options.
If you already have a vimrc file with your configuration, you can do one of the following:
Include the configuration from vimrc with the
source
command in your ideavimrc file:source ~/.vimrc
This way you can also include other commands in your ideavimrc file, which will be applied only to your Vim in IntelliJ IDEA and will not affect actual Vim configuration.
If you don't want to use your Vim configuration, you can rename .vimrc to .ideavimrc.
Create ideavimrc as a symlink to vimrc if you don't want to modify your Vim in IntelliJ IDEA compared to actual Vim configuration:
WindowsmacOSLinuxmklink _ideavimrc _vimrc
ln -s "$HOME/.vimrc" "$HOME/.ideavimrc"
ln -s "$HOME/.vimrc" "$HOME/.ideavimrc"
IdeaVim allows you to map IDE features using action IDs.
Press CtrlShift0A and type
IdeaVim: Track Action Ids
.Toggle the feature on using the switcher on the right.
Now the IDE will be showing you IDs of actions that you click with the mouse in a popup notification at the bottom of the screen and in the Notifications tool window. Note that some actions do not have an ID.
Click Copy Action Id to copy an ID or Stop Tracking to disable the tracking mode.
In the ideavimrc file, map an action using the
map
command and the<Action>
keyword, for example:map \r <Action>(ReformatCode)
Press CtrlShift0O to reload the changes.
tip
You can also execute actions as Ex commands. For more information, refer to IdeaVim documentation.
Thanks for your feedback!