I have been using Vim seriously™ for about a year now. As I have learned, and other Vim acolytes will probably tell you, learning Vim works best if you use it a lot. But what if you don’t feel quite ready to get rid of the tools you have come to love in favor of Vim?
I myself am a big fan of Jetbrains products. In fact I have been ever since I started my developer career - thanks to Resharper which made working with VisualStudio much more fun. Even after a year of Vim, I don’t feel quite ready to ditch my favorite IDEs. This issue, if you can call it that, brought me to the question: What to do if you don’t want to go full Vim but also want to improve your Vim skills at the same time? Well, for a start you can use Vim keybindings… everywhere.
The worst thing about Vim...— Mastering Vim (@MasteringVim) February 11, 2019
Do you have the same problem? pic.twitter.com/spFZJayIak
For Jetbrains products there is the great IdeaVim plugin (which, regardless of its name, works for any Jetbrains IDE I have come across so far), and this post is about using it. A word of warning before I get started: IdeaVim brings Vim keybindings and some functions from Vim to Jetbrains IDEs, but don’t expect everything you know from Vim to work in, say, RubyMine. I’ll discuss some caveats of using IdeaVim at the end of this post.
Installation and Configuration
You can install IdeaVim through the Jetbrains Marketplace. After restarting your IDE, you probably notice fairly quickly that some of your shortcuts stop behaving like you expect them to. This is because these shortcuts refer to both IDE actions and Vim actions - which results in a conflict that you will have to resolve. For example,
Ctrl + W triggers the
Expand Selection action in, say, IntelliJ Idea, but refers to window actions (e.g.
<C-W>v) in Vim. Don’t worry, we’ll sort that out shortly.
IdeaVim allows you to configure whether a shortcut should invoke an Idea action or an IdeaVim action using the Vim Emulation settings, which you can find in
Settings > Editor > Vim Emulation. Per default, whenever you invoke a conflicting action IdeaVim will assign itself as the handler. Because the entire point here is to get used to Vim shortcuts I recommend you use Vim actions for every conflicting shortcut. So your emulation settings should look like this:
Apart from these emulation settings IdeaVim can be configured, just like regular Vim, using a dotfile, in this case the
.ideavimrc file which can be found in your home directory. If its not there, create it:
$ touch ~/.ideavimrc
Here you can configure your IdeaVim installation to your liking. For example, you may define keyboard shortcuts here or set up various default settings. Customization of Vim is a pretty big topic, so I refer you to the Vim Documentation. Note that you can also assign Idea actions to shortcuts here, for example
map <C-e> :action RecentFiles<CR>
will trigger the Recent Files action when
Ctrl+E is pressed. This is actually the same as the default setting, but handled by Vim, which allows for greater customization and, coincidentally enables you version your shortcuts using the dotfile manager of your choice. For a full list of available actions either use the
:actionlist command in Idea or have a look at this Gist. Here are some mappings I myself use:
map <C-e> :action RecentFiles<CR> map <C-n> :action GotoClass<CR> map <C-s> :action EditorSelectWord<CR> map <Leader>s :action SaveAll<CR> map <Leader>b :action GotoDeclaration<CR> map <Leader>u :action GotoSuperMethod<CR>
set surround set multiple-cursors
Caveats and Issues
IdeaVim is great, but it is still just a substitute for the ‘Real Thing’. There are a couple of issues and problems, some of which can be worked around. For one IdeaVim is limited in its functionality. Plugins and various commands that you would know from Vim simply won’t work. For example
augroup are not supported. The plugins mentioned above are also the only ones currently supported.
The fix for all issues related to missing functionality in IdeaVim is simple: Use Vim!
You can set up Vim as an external tool and open it on the current file if you quickly need to do something that requires a Vim plugin. Follow this guide but change the relevant values to use Vim instead.
This will open Gvim on the current line in the current file. You can assign a shortcut to this command for maximum efficiency.
Apart from limitations of IdeaVim there are some bugs and issues specific to IdeaVim that may cause you some headaches. Here are some I came across, together with possible fixes:
Structural Code Selections not working
Selecting content by some action, such as the
Extend Selection) does not mean it is visually selected. That means that triggering the
EditorSelectWord action and then performing something like
d on it will not do anything. The issue is well documented here and here. To work around this issue, you have to enter visual mode after triggering the action - which, granted, is a bit of a hassle.
Terminal Bell Sounds
When using IdeaVim, you will find that entering normal mode will trigger a bell sound. This can be disabled by adding the following lines to your
.ideavimrc, as seen on SuperUser:
set visualbell set noerrorbells
When using IdeaVim, you will find that sometimes your editor becomes unresponsive. For me, this doesn’t happen too often, so it is not a deal-breaker. However, if it turns out to be too annoying you can turn to this SO thread and see if any of the fixes outlined there help you.
Keybindings interfere with Tool Windows
This one is a real bummer. When IdeaVim is activated you may find it difficult to use certain tool windows in your IDE, for example the Database editor. Vim keybindings apply here as well, and that means you will have to repeatedly enter and exit insert mode to enter data. I have not found a way to work around this issue.
I have been using IdeaVim for a couple of months now, and although there are some issues with it, I feel that it has helped me improve my Vim-Foo a fair bit. I hope it will for you, too!