Is there a way to get IdeaVIM to honor the mappings from my .vimrc file?

VimIdeavim

Vim Problem Overview


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.

Vim Solutions


Solution 1 - Vim

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.)

Solution 2 - Vim

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/

Solution 3 - Vim

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

Solution 4 - Vim

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:

  1. Grab the IdeaVIM source code. >https://github.com/JetBrains/ideavim

  2. You can follow the instructions under "Development" on that page to set up your dev environment for the plugin.

  3. Now that your IdeaVIM project is all setup, open this file: com.maddyhome.idea.vim.key.RegisterActions.java

  4. 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.

  5. 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)})
    });

  6. 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

  7. 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.

  8. Give it a whirl! Should be able to use 'jk' as your exit insert mode shortcut now!

Solution 5 - Vim

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!

Solution 6 - Vim

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.

Solution 7 - Vim

To get it working on windows 7 create .ideavimrc in C:\Users[username]

Worked for me.

Solution 8 - Vim

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

Solution 9 - Vim

I'm using vim (version 0.57) for 2 days :D and I hated to exit insert mode with ESC key In jet brains just look down in the right side you're gonna see vim logo then > Open ~/.ideavimrc

enter image description here

and type :imap ii <ESC> this is gonna exit insert mode with double i (put whatever) and save .ideavimrc file and restart your IDE

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHank GayView Question on Stackoverflow
Solution 1 - VimjbylerView Answer on Stackoverflow
Solution 2 - Vimars-longa-vita-brevisView Answer on Stackoverflow
Solution 3 - VimAlan Zhiliang FengView Answer on Stackoverflow
Solution 4 - VimgnilView Answer on Stackoverflow
Solution 5 - VimruffinView Answer on Stackoverflow
Solution 6 - Vimmaher.csView Answer on Stackoverflow
Solution 7 - VimItai NoamView Answer on Stackoverflow
Solution 8 - VimGabriel AtheosView Answer on Stackoverflow
Solution 9 - VimFunCoderView Answer on Stackoverflow