Vim in IntelliJ IDEA
IDEA is one of the IDEs with relatively good support for Vim with the IdeaVim Plugin2. Even though one can come close to functionality offered by IntelliJ with either Vim or Emacs Plugins, I find that IntelliJ IDEA is a must have for Scala development, in my experience. However, with IdeaVim Plugin you can still get the best of both world’s by leveraging your Vim editing muscle memory via IdeaVim plugin.
IdeaVim can be customised in a similar way to Vim by editing a configuration
I would refer to my current config file to get the full details2, but following are some of the more useful settings to bring the experience closer to full Vim capabilities.
" Emulated Plugins set surround " Use Idea to join lines smartly set ideajoin " Copy to system clipboard as well set clipboard+=unnamed " Multiple cursors support set multiple-cursors
- Vim surround enables support for popular vim-surround support3.
- ideajoin is a recent setting which emulates IntelliJ’s builtin line join
semantics when you use Vim commands to join lines, such as
- As with Vanilla Vim, by default, yanked text will not be put in to system
clipboard. However, it is quite handy to have consistent behaviour when it
comes to copying as if you didn’t use IdeaVim in the first place. With
clipboard+=unnamedsetting, text you copy within IDEA will also be copied to the system clipboard.
My settings are quite tailor made to my work setup, so it wouldn’t be a good idea to copy them verbatim. I would suggest taking useful settings from there for your own personalised setup. That is also what I’ve done from multiple sources, some of which I’ve referenced in comments in the config file itself.
Finding out available actions
To get a list of available actions which you can bind keys for, run the following command in normal mode in IDEA after enabling IdeaVim plugin.
This command is pretty useful to extend key bindings because IntelliJ Plugins actions are also avaialble via a unified action system.
Summon real Vim for quick edits
Inevitably you’ll find that IdeaVim, though really good, does not really support all the myriad advanced ways you do ediging in vanilla Vim. For those times, I recommend adding a leader key binding as follows to open a Vim instance.
" External GVim nmap <leader>v :action Tool_External Tools_gvim<cr>
Interested readers can find my current
.ideavimrc file here.
For this binding to work, first you will need to setup gvim as an external tool.
Setting up GVim as an external tool in IDEA
Make sure to tick the setting for
Synchronize files after execution setting
as shown above in the settings window image.
I find that this is pretty useful for doing block edits in Vim which I’m more used to than doing them in IntelliJ editor.
I have used similar settings for MacVim on macOS and Windows GVim as well, although in the latter case I have not tested Vim client-server behaviour. This is a simple usability improvement to reuse existing Vim instance for multiple files opened via IntelliJ.
For ease of copying, here’s the full command.
--servernaem IdeaVim --remote-silent "+call cursor($LineNumber$, $ColumnNumber$)" "$FilePaths$"