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

32,179

Solution 1

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

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

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

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

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!

Share:
32,179
Hank Gay
Author by

Hank Gay

I like to spend time with my lovely wife, our two beautiful daughters, and our dog. I'm also a fan of geek humor, and I've been known to flip out and write code… elegant code, if I'm really lucky.

Updated on July 05, 2022

Comments

  • Hank Gay
    Hank Gay almost 2 years

    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.

  • Hank Gay
    Hank Gay almost 13 years
    I was afraid this was the answer, but thanks for the workaround, and the excellent source references.
  • mohamd Agoumi
    mohamd Agoumi about 11 years
    I can back this up. IdeaVim seems to read your ~/.vimrc file, but silently ignore any commands and settings it doesn't support. I like to turn off the error bell, so I have :set noerrorbells in my .vimrc. But IdeaVim doesn't support that. It does, however, support :set visualbell. Even though it doesn't flash the screen as you'd expect. That serves to silence the bell though. So I included that in my .vimrc before :set noerrorbells and all is good.
  • gregoltsov
    gregoltsov over 10 years
    @HankGay There is currently an issue on JetBrains' bug tracker addressing precisely this problem. It's already set to major priority, but vote it up anyway!
  • ruffin
    ruffin about 10 years
    Would need to know your platform (pretty obviously not Windows ;^D) and what's in the vimrc (pastebin?) to be able to help fully -- note that this [my] answer was mostly for Windows (that's where I tried it out and had things partially work). Oleg's pretty good about answering too, if he's still involved with IdeaVIM.
  • baldrs
    baldrs almost 10 years
    It has been fixed in 0.33 and now the plugin does honor the key mappings(there were a pull request on github that added that feature)
  • Erik Corry
    Erik Corry over 8 years
    This works pretty well now, I think. But I found I had to use :imap instead of :map! to remap in insert mode. In vim, both work.
  • Jay Bhavsar
    Jay Bhavsar over 6 years
    There is no ~/.ideavimrc in my system. Also vim command scriptnames does not work. Is there any way to figure out where my ~/.ideavimrc file is?
  • jbyler
    jbyler over 6 years
    @JayBhavsar, you have to create the file. ~ means your home directory. So create a file called .ideavimrc in your home directory, and put settings you want in there.
  • SanD
    SanD about 6 years
    if you don't have the file ~/.ideavimrc then you can just simply create it. Just write source ~/.vimrc or source wherever your .vimrc file is. Restart pycharm.
  • Anenth
    Anenth almost 6 years
    Its not working for me, ~/.ideavimrc is simply getting ignored
  • Kyle Strand
    Kyle Strand almost 5 years
    I have IdeaVim 0.51; it looks like it does not automatically source .vimrc, so .ideavimrc is still needed.
  • Kyle Strand
    Kyle Strand almost 5 years
    Ah, the README confirms this: github.com/JetBrains/ideavim/blob/…
  • Armali
    Armali almost 4 years
    You seem to never have been inclined to type Hawaii.