有没有办法让 IdeaVIM 遵循我的 .vimrc 文件中的映射?

发布于 2024-10-31 08:08:35 字数 232 浏览 1 评论 0原文

我最近(再次)大量使用 vim,现在我的 .vimrc 文件中有大量自定义内容。我意识到并不是其中的所有内容在 IDEA 插件的上下文中都有意义,但如果将 jj 重新映射到 Esc< 之类的事情,我真的会喜欢它/code> 被选中并受到尊重。有办法做到这一点吗?也就是说,无需手动调整 IDEA 键盘映射中的所有内容。

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

浅黛梨妆こ 2024-11-07 08:08:35

更新的答案:IdeaVim 版本 0.35(2014-05-15 发布)从 ~/.ideavimrc 读取设置和键绑定。如果您想包含来自 ~/.vimrc 的映射,可以将 source ~/.vimrc 放入该文件中。

0.33和0.34直接读取~/.vimrc

0.33(2014年4月28日发布)是第一个实现VIM-288的版本,包括映射< kbd>jjESC。它工作得很好,IDEA 首选项中有一个新的 Vim Emulation 部分,列出了 ~/.vimrc 映射和 Intellij 映射之间的所有冲突,并让您解决冲突通过将按键分配给 IDEA 或 IdeaVim。以下是 Twitter 上的发布公告

(注:我不是作者,只是一个满意的用户。)

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

傲世九天 2024-11-07 08:08:35

更新:是的!请参阅下面的答案。

简短的回答:不。

我也一直在尝试这样做,特别是因为我有一个相当复杂的 .vimrc ,多年来我已经习惯了。

无论如何,有一个解决方法(某种程度上)。 IdeaVim 设置存储在主文件夹 (C:\Users\) 内 .IntelliJIdea10/config/keymaps 文件夹中名为 vim.xml 的文件中;(在 Windows 上)。您可以编辑 XML 以添加您想要的内容。例如,我添加了以下几行来通过按 F2 而不是键入 :w! 来保存文件:

<action id="SaveAll">
<keyboard-shortcut first-keystroke="F2"/>
</action>

但是,我不知道如何添加函数等内容或 vim 设置(这是我通常使用 .vimrc 的用途)。

PS 这可以解释为什么不使用 .vimrc (强调我的):

出于好奇,该插件正在
书面没有任何参考
VIM 源代码
(除了
正则表达式处理)。我是
基本上使用优秀的VIM
文档和 VIM 本身作为
参考以验证正确的行为。
来源:http://ideavim.sourceforge.net/

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/

旧伤慢歌 2024-11-07 08:08:35

根据插件存储库中的描述(https://github.com/JetBrains/ideavim) ,您可以通过创建一个文件“~/.ideavimrc”及其内容来实现这一点:

source ~/.vimrc

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
寂寞美少年 2024-11-07 08:08:35

看起来 IdeaVIM 问题 # VIM-288 (编辑,更新:参见 jbyler 的答案,VIM-288 现已修复)将解决当问题得到解决时你的问题。我也在寻找一种让“jk”退出插入模式而不是使用 Escape 键的方法。我不是 IntelliJ 插件方面的专家,但我设法修改了 IdeaVIM 源代码,以便将“jk”快捷方式硬编码在其中。然后我所要做的就是重新部署插件并使用它而不是官方版本。我是这样做的:

  1. 获取 IdeaVIM 源代码。

    <块引用>

    https://github.com/JetBrains/ideavim

  2. 您可以按照“开发”下的说明进行操作”,为插件设置开发环境。

  3. 现在您的 IdeaVIM 项目已全部设置完毕,请打开此文件:
    com.maddyhome.idea.vim.key.RegisterActions.java

  4. 这个文件似乎包含所有 Visual/Insert/Normal 模式命令及其相应的键绑定。对于我更改“退出插入模式”键绑定的示例,请查找“VimInsertExitMode”。您需要在该代码块中添加一行作为新快捷方式。

  5. 以下是我编辑后的代码部分的外观:

    parser.registerAction(KeyParser.MAPPING_INSERT, "VimInsertExitMode", Command.Type.INSERT, new Shortcut[]{
        新快捷方式(KeyStroke.getKeyStroke('[', KeyEvent.CTRL_MASK)),
        新快捷方式(KeyStroke.getKeyStroke(KeyEvent.VK_C,KeyEvent.CTRL_MASK)),
        新快捷方式(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)),
        新的快捷方式(“jk”),
        新快捷方式(新KeyStroke[]{KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SLASH,KeyEvent.CTRL_MASK),
            KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_MASK)})
    });

  6. 现在部署项目(制作 .jar)并将其添加到您的插件文件夹中;我按照以下说明进行参考:

    <块引用>

    http://confluence.jetbrains .com/display/IDEADEV/Getting+Started+with+Plugin+Development#GettingStartedwithPluginDevelopment-anchor5

  7. 您可能需要从键盘映射文件夹中保存 Vim.xml 文件,我不确定。我删除了我的文件,然后在重新启动 IntelliJ 时重新制作了它。

  8. 试一试!现在应该可以使用“jk”作为退出插入模式快捷方式!尝试

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!

只是偏爱你 2024-11-07 08:08:35

您知道,我在 Windows 上的主文件夹中(通常是 C:\Users\yourLogin )中使用 .vimrc 取得了一些成功。看来这是设计使然。 Oleg 在这里提到 IdeaVIM 使用 VIm 命令的子集。

http://youtrack.jetbrains.com/issue/VIM-134#tab=Comments

看来您需要登录才能查看 youtrack 系统上的评论。

奥列格·什皮诺夫
2011年8月15日 18:12

IdeaVIM 插件从 .vimrc 文件加载一些配置数据,但是 vim 插件支持
不可用,也不会可用,因为它需要重写所有 VIM 运行时
IdeaVim 插件。

请注意,如果您使用的是 Windows,则必须将文件命名为 .vimrc,而不是 _vimrc。

至少可以与setignorecase一起使用!

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!

陪我终i 2024-11-07 08:08:35

IdeaVim 现在(至少早在 0.35 版本)支持有限数量的设置命令,以及地图及其变体。要自动获取它们,请将您的设置放入 ~/.ideavimrc 中。

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.

泪眸﹌ 2024-11-07 08:08:35

为了让它在 Windows 7 上工作,在 C:\Users[用户名] 中创建 .ideavimrc

为我工作。

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

Worked for me.

彼岸花ソ最美的依靠 2024-11-07 08:08:35

我昨天才想出如何做到这一点。我可以通过运行以下命令将我的 .vimrc 符号链接到我的 ideavim 设置:

ln -s $HOME/.vimrc $HOME/.ideavim

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
迷荒 2024-11-07 08:08:35

我使用 vim(版本 0.57)2 天了 :D 我讨厌用 ESC 键退出插入模式
在 jet Brains 中,只要往下看右侧,你就会看到 vim 徽标,然后 >打开 ~/.ideavimrc

在此处输入图像描述

并输入 :imap ii 这将使用双 i 退出插入模式(输入任何内容)
并保存 .ideavimrc 文件并重新启动 IDE

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文