30

I'm used to both vim and IntelliJ default hotkeys. I'd like to not to have to change any of them - I'd rather like to be able to use conflicting IntelliJ bindings, like CTRL-P for example, after some kind of escape key.

Conflict balloon and my research wasn't too helpful. Only thing that I've found is that I can turn vim plugin off with a hotkey, and then back on after I'm done, but I have to remember to turn it one every time.

Is there any solution for my problem?

Mihai
  • 23,092
  • 7
  • 58
  • 73
Thirteenth Seeker
  • 313
  • 1
  • 3
  • 5

5 Answers5

65

I made .ideavimrc that contains bindings for all conflicted mappings. Maybe it'll be usefull to someone.

imap jj <Esc>

let mapleader = " "
map <leader>a :action $SelectAll<CR>
map <leader>b :action GotoDeclaration<CR>
map <leader>c :action $Copy<CR>
map <leader>d :action EditorDuplicate<CR>
map <leader>e :action RecentFiles<CR>
map <leader>f :action Find<CR>
map <leader>g :action GotoLine<CR>
map <leader>h :action TypeHierarchy<CR>
map <leader>i :action ImplementMethods<CR>
map <leader>m :action EditorScrollToCenter<CR>
map <leader>n :action FileChooser.NewFolder<CR>
map <leader>o :action OverrideMethods<CR>
map <leader>p :action ParameterInfo<CR>
map <leader>q :action QuickJavaDoc<CR>
map <leader>r :action Replace<CR>
map <leader>s :action SaveAll<CR>
map <leader>t :action Vcs.UpdateProject<CR>
map <leader>u :action GotoSuperMethod<CR>
map <leader>v :action $Paste<CR>
map <leader>w :action EditorSelectWord<CR>
map <leader>x :action $Cut<CR>
map <leader>y :action EditorDeleteLine<CR>
map <leader>[ :action EditorCodeBlockStart<CR>
map <leader>] :action EditorCodeBlockEnd<CR>
pokkie
  • 519
  • 1
  • 8
  • 22
melihovv
  • 1,025
  • 1
  • 10
  • 14
23

I just turn VIM plugin off, execute keystroke, then turn it back on. I have ^Z bound to the VIM Emulator command for this purpose and it's enough for me. To set this up, go to Preferences... => Keymap, search for "vim emulator", and right-click on the command name to assign a shortcut.

But if you have a limited set of IntelliJ commands you want to use with a prefix key, you could pick the prefix key, make sure it is unbound in IntelliJ, and then use it in your ~/.ideavimrc along with the original binding you wan to invoke.

For example, ^D in VIM is "Scroll window Downwards" and in IntelliJ (with keymap "Mac OS X 10.5+") is "Debug". If you want to be able to use both:

  • choose a prefix key that's not bound in IntelliJ, say ^Z
  • in Other Settings => Vim Emulation, find shortcut ^D and set the handler to Vim.
  • In your ~/.ideavimrc, add the following mapping:

    nnoremap <C-Z><C-D> :action Debug<CR>

Now you can type ^D for the Vim action scroll down, or ^Z^D for the IntelliJ action Debug, without actually disabling IdeaVIM. You'll of course have to add a mapping to your ~/.ideavimrc for each IntelliJ command you want to execute this way, but if you have a limited number you can set them up once and be done with it.

jbyler
  • 6,013
  • 3
  • 27
  • 36
  • That's a start of an interesting idea. I guess it's possible to parse IntelliJ and IdeaVim keymap files, and then make `.ideavimrc` that contains bindings for all conflicted mappings. I could do that and fit in in your answer and then accept it; I've just yet to find respective files (I've only found custom IDEA keymap .xml file and no default so far). – Thirteenth Seeker Aug 17 '15 at 11:43
  • 2
    How did you configure vimemulator with ^Z? I'm not able to do it. – Onewildgamer Jul 14 '18 at 10:22
  • 1
    @Onewildgamer I second this. "I just turn VIM plugin off, execute keystroke, then turn it back on. I have ^Z bound to the VIM Emulator command for this purpose and it's enough for me." -- how do you do this? – Code Wiget Nov 23 '19 at 23:43
  • 2
    @Ryan, I just edited the answer to add instructions. – jbyler Nov 27 '19 at 22:06
  • To find all actions, type `:actionlist`. Here is what i did to bind _VCS/Commit_ action: 1) In _IdeaVim / Settings_ set _Ctrl+K_ _"Commit..."_ to _IDE_ handler; 2) list all actions with `:actionlist` command; 3) found _C-K_ there and copied action name - _CheckinProject_; 4) In _IdeaVim / Settings_ set _Ctrl+K "Commit..."_ to _Vim_ handler; 5) add map in `~/.ideavimrc` - `nnoremap :action CheckinProject`; 6) `:source ~/.ideavimrc`. – Dimon Apr 23 '20 at 09:38
5

Adding onto the excellent answer by @melihovv, I have added the Run, Debug, and Choose Configuration actions to my ~/.ideavimrc.

map <leader>dd :action Debug<CR>
map <leader>cd :action ChooseDebugConfiguration<CR>
map <leader>rr :action Run<CR>
map <leader>cr :action ChooseRunConfiguration<CR>
John Slavick
  • 9,145
  • 4
  • 25
  • 23
1

A keymap without any bindings here: to be used, so one could start from clean slate configuring the .ideavimrc

animaacija
  • 110
  • 7
  • 25
0

A simple option may also be to use insert mode for IntelliJ Keybindings. I'm just starting out with ideavim and this seems to do it for me, for now..

alex0ptr
  • 19
  • 3