Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to map keys for IdeaVim's normal mode to editor's action?

I am using JetBrains' phpstorm with the IdeaVim plugin.

I am wondering if I can bind keys in normal mode to editor actions.

For example, I used to have mapped Ctrl+B to Navigate > Declaration. Yet Ctrl+B is a vi motion to go one page backwards and that is ok.

I know I can configure a keyboard shortcut to a different one, e.g. Ctrl+Shift+B , yet to keep things simpler I want to have a key in ideavim's command mode mapped to that functionality, e.g. ;.

So that pressing ; in command mode would trigger the action of Declaration witin phpstorm.

How can I achieve this?

like image 202
k0pernikus Avatar asked Jan 06 '16 12:01

k0pernikus


2 Answers

To give a specific answer for exactly what you asked to map: put this into your ~/.ideavimrc:

nnoremap ; :action VimGotoDeclaration<CR>

To find the action name, I typed :actionlist declaration which gives a subset of action names that include the word "declaration" in the action name.

As others have noted, you might also prefer to use one of the existing mappings rather than adding a new one.

like image 75
jbyler Avatar answered Sep 25 '22 00:09

jbyler


what you wanted go to declaration is built in command in vim. You don't have to use IDEA's actions.

gd (goto declaration) is the thing you are looking for.

So you just press (normal mode) gd, to see what is gonna happen.

In a normal vim, do :h gd to check details.

like image 36
Kent Avatar answered Sep 24 '22 00:09

Kent