39

In Vim we can use Ctrl + N or Ctrl + P to finish code completion. How to configure it in IdeaVim for IntelliJ?

laike9m
  • 14,908
  • 16
  • 92
  • 123
Simon Su
  • 1,633
  • 4
  • 17
  • 19

6 Answers6

34

Alt + / and Alt + Shift + / work both in plain IntelliJ and with IdeaVim installed.

Please see documentation on JetBrains page - it's called Hippie Completion (newer versions call this completion Cyclic Expand Word).

And of course you can always use Ctrl + Space, Ctrl + Shift + Space, Ctrl + Alt + Space.

Slowbad
  • 65
  • 1
  • 8
Michal Kordas
  • 9,161
  • 7
  • 42
  • 81
  • 1
    Thianks a lot, it works. Do you know if there are any shortcut keys which can show a "list" like vim – Simon Su May 10 '15 at 08:27
  • `Ctrl + Space`, `Ctrl + Shift + Space` and `Ctrl + Alt + Space` are the only I know to show the list of completions. – Michal Kordas May 10 '15 at 08:34
  • 7
    Did anyone manage to map `Ctrl + P` to behave the same as `Alt + /`? I added new keyboard shortcut but hitting `Ctrl + P` does not work. There is no conflicting shortcut and I also tried to remove `Alt + /` mapping. No success=( – Ikar Pohorský Aug 27 '15 at 10:36
  • 2
    @IkarPohorský - It works for me without any problems in the latest EAP of IntelliJ 15. – Michal Kordas Aug 28 '15 at 06:36
  • 6
    Thanks, but I don't think this is an acceptable answer. I've been using vim for over 25 years and use it daily in multiple environments, so having to use 'special' keys for everyday functions, just for this one environment, doesn't make IdeaVIM sound like a good emulator. – Michael Scheper Oct 15 '18 at 19:19
  • @IkarPohorský Did you finally figure out how to do it? – Parth Sharma Mar 01 '19 at 11:02
  • @ParthSharma: yup, see the answer from: softw – Ikar Pohorský Mar 01 '19 at 17:48
20

I could not get CTRL-N and CTRL-P to work after mapping them to "Cyclic Expand Word" and "Cyclic Expand Word (Backward)" in IDEA 2016.2.5 (while running IdeaVIM). Both keystrokes just did nothing.

The solution was to additionally select "Settings" from the File Menu, then "Other Settings" -> "Vim Emulation", and set the "Handler" for Ctrl+N and Ctrl+P to "IDE" instead of "Vim".

Ikar Pohorský
  • 3,559
  • 2
  • 29
  • 49
softw
  • 201
  • 2
  • 2
  • 4
    This is the correct answer for IDEA 2016.3.4. The second part of this answer - changing the handler from vim to ide - is the crucial step, but the keymap for cyclic expand word is also necessary as mentioned in other answers as well as this answer. – Jason Feb 09 '17 at 15:34
  • 1
    You're a genius. – laike9m Oct 17 '17 at 09:37
11

This is the way I found to make the word completion work with CTRL-N and CTRL-P, while still having the shortcuts work for DOWN and UP in lists.

In Settings -> Keymap, map CTRL-N and CTRL-P to Down and Up respectively. Then, in the Other Settings -> Vim Emulation, set CTRL-N and CTRL-P handlers to Vim.

Finally, add the following to your .ideavimrc

imap <C-n> <ESC>:action HippieCompletion<CR>a
imap <C-p> <ESC>:action HippieBackwardCompletion<CR>a
Jaysee
  • 111
  • 1
  • 4
  • This used to work perfectly. Now after some update of PyCharm/ideaVim (not sure which is the culprit), this doesn't work... It allows hippie completion (aka cyclic expand) but Up/Down in **completion menus** does no longer work. I tried multiple things but couldn't get both to work again. Any idea how to mkae **both** things work again? – avivr Nov 05 '19 at 11:10
  • This is working for me with no other changes (i.e., `` and `` handler is set to the default Vim). I am using IntelliJ `2020.3.2` and IdealVim `0.64`. – haridsv Feb 18 '21 at 15:23
9

Add the following keymaps: Ctrl+N to Down and Ctrl+P to Up

So you can easily navigate in the completions menus.

leadrien
  • 426
  • 2
  • 7
  • That's assuming there _is_ a 'completions' menu. The problem is when we're trying to auto-complete a string, e.g. `MY_ENV_VALUE = os.env["MY_ENV_VALUE"]`. In the real vim, Ctrl+P after the second capital M completes the required string. – Michael Scheper Oct 15 '18 at 19:24
2

File->Settings->Keymap->search keywords "cyclic expand word"

1

As of IntelliJ IDEA Community Edition v2020.1.1 with IdeaVim v0.57 plugin, what enables me to auto-complete code as well as cycling through suggestions with with Ctrl+N is the following:

  • File -> Settings -> Keymap
  • On the search bar type: hippie
  • Add Keyboard Shortcut to "Cyclic Expand Word" Ctrl+N (If prompted, remove other assignments)
  • Add Keyboard Shortcut to "Cyclic Expand Word (Backward)" Ctrl+P (If prompted, remove other assignments)

If like me, you had added the following to your .ideavimrc:

 imap <C-n> <ESC>:action HippieCompletion<CR>a
 imap <C-p> <ESC>:action HippieBackwardCompletion<CR>a

Comment those two lines out by prepending them with ", or delete them.

Hank Adler
  • 11
  • 2