I've recently gotten into vim in a big way (again), and I now have a ton of customization in my .vimrc
file. I realize that not everything in there would make sense in the context of an IDEA plugin, but I'd really like it if things like remapping jj
to Esc
were picked up and honored. Is there a way to do that? Without needing to manually tweak all that stuff in IDEA's keymap, that is.
Thanks.
Update: Yes! See answer below.
Short answer: no.
I've been trying to do this too especially because I have quite a complex .vimrc
that I've become used to over the years.
Anyway, there is a workaround (sort of). IdeaVim settings are stored in a file called vim.xml
in the .IntelliJIdea10/config/keymaps
folder inside your home folder (C:\Users\<user_name>
on Windows). You can edit the XML to add stuff that you want. For instance, I added the following lines to save a file by hitting F2
instead of typing :w!
:
<action id="SaveAll">
<keyboard-shortcut first-keystroke="F2"/>
</action>
However, I don't see how we can add things like functions or vim settings (which is what I'd typically use a .vimrc
for).
P.S. This might explain why a .vimrc is not used (emphasis mine):
For the curious, the plugin is being
written without any reference to the
VIM source code (except for the
regular expression handling). I'm
basically using the excellent VIM
documentation and VIM itself as a
reference to verify correct behavior.
Source: http://ideavim.sourceforge.net/
Updated answer: IdeaVim version 0.35 (released 2014-05-15) reads settings and key bindings from ~/.ideavimrc
. You can put source ~/.vimrc
in that file if you want to include mappings from ~/.vimrc
.
0.33 and 0.34 read ~/.vimrc
directly.
0.33 (released 2014-04-28) was the first version to implement VIM-288, including things like mapping jj to ESC. It works great, and there's a new Vim Emulation section in the IDEA preferences that lists all the conflicts between ~/.vimrc
mappings and Intellij mappings, and lets you resolve the conflicts by assigning the keys to either IDEA or IdeaVim. Here is the release announcement on twitter.
(Note: I'm not the author, just a satisfied user.)
It looks the IdeaVIM issue # VIM-288 (edit, update: see jbyler's answer, VIM-288 now fixed) will solve your problem when that gets fixed. I, too, was looking for a way to have 'jk' exit insert mode instead of using the Escape key. I'm no expert on IntelliJ plugins, but I managed to modify the IdeaVIM source code so that the 'jk' shortcut was hardcoded in there. All I had to do then was re-deploy the plugin and use that instead of the official version. Here's how I did it:
Grab the IdeaVIM source code.
https://github.com/JetBrains/ideavim
You can follow the instructions under "Development" on that page to set up your dev environment for the plugin.
Now that your IdeaVIM project is all setup, open this file:
com.maddyhome.idea.vim.key.RegisterActions.java
It seems this file has all the Visual/Insert/Normal mode commands and their corresponding key-bindings. For my example of changing the "exit insert mode" key bind, Look for "VimInsertExitMode". You'll need to add a line to this block of code for your new shortcut.
Here is how the section of code looked after I edited it:
parser.registerAction(KeyParser.MAPPING_INSERT, "VimInsertExitMode", Command.Type.INSERT, new Shortcut[]{
new Shortcut(KeyStroke.getKeyStroke('[', KeyEvent.CTRL_MASK)),
new Shortcut(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_MASK)),
new Shortcut(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)),
new Shortcut("jk"),
new Shortcut(new KeyStroke[]{KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SLASH, KeyEvent.CTRL_MASK),
KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_MASK)})
});
Now deploy the project (make a .jar) and add it to your plugins folder; I followed these instructions for reference:
http://confluence.jetbrains.com/display/IDEADEV/Getting+Started+with+Plugin+Development#GettingStartedwithPluginDevelopment-anchor5
You might need to save your Vim.xml file from your keymaps folder, I'm not sure. I deleted mine and then it was re-made when I restarted IntelliJ.
Give it a whirl! Should be able to use 'jk' as your exit insert mode shortcut now!
You know, I've had some success with .vimrc in my home folder on Windows, so typically C:\Users\yourLogin . It would appear that's by design. Oleg mentions that IdeaVIM uses a subset of VIm commands here.
http://youtrack.jetbrains.com/issue/VIM-134#tab=Comments
Looks like you need to be logged in to see comments on the youtrack system.
Oleg Shpynov
15 Aug 2011 18:12
IdeaVIM plugin loads some configuration data from .vimrc file, however vim plugins support
is not and won't be available, because is requires to rewrite all the VIM runtime within
IdeaVim plugin.
Note that you have to name the file .vimrc, not _vimrc, if you're on Windows where you might expect the latter.
Works with set ignorecase
at least!
According to the description in the repository of the plugin (https://github.com/JetBrains/ideavim), you can achieve that by create a file "~/.ideavimrc" with its content:
source ~/.vimrc
IdeaVim now (at least as early as 0.35) supports a limited number of set commands, as well as map and its variations. To have them sourced automatically, put your settings in ~/.ideavimrc.
To get it working on windows 7 create .ideavimrc in C:\Users[username]
Worked for me.
I just figured out how to do this yesterday. I was able to symbolically link my .vimrc to my ideavim settings by running the following command:
ln -s $HOME/.vimrc $HOME/.ideavim