Reputation: 66460
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?
Upvotes: 5
Views: 4051
Reputation: 7847
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.
Upvotes: 15
Reputation: 16838
You can use <C-]>
(Ctrl+]) for following references (jumping to the declaration is an example of a reference) and <C-O>
for going back. You can also map these Vim-style shortcuts using the map
commands similar to the original Vim.
Upvotes: 0
Reputation: 195029
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.
Upvotes: 4