How to map an <Action> using IdeaVim in PhpStorm?

1.5k Views Asked by At

The phpStorm plugin for vim: https://github.com/JetBrains/ideavim, is configurable via .ideavimrc (as per the docs). There is an example from the docs:

""" Mappings --------------------------------
map <leader>f <Plug>(easymotion-s)
map <leader>e <Plug>(easymotion-f)

map <leader>d <Action>(Debug)
map <leader>r <Action>(RenameElement)
...

There is the <Action> mapping, where in parethesis is the action IDE should perform. Now there is a list of all supported actions in supported actions.

I would like to map to <leader>] an action to move to next tab. In the supported actions link above, I found the action:

 * |gt|                   {@link com.maddyhome.idea.vim.action.motion.tabs.MotionNextTabAction} 

(Or I think, that is the right action, "to move to next tab"). So the I would expect the mapping to be:

map <leader>] <Action>(MotionNextTabAction)

But of course, that does not work. The action name is probably wrong, but I have no other reference then the "supported action list" from the link. So how should look the mapping? How to translate between the list and the "real" action name?

2

There are 2 best solutions below

0
On

The name of the action is NextTab. This list is actually not a list of actions, but the list of links to implementation classes for developers. (yes, we should actually update it to be more user-friendly).

Regarding the action name: usually I suggest to use "track action IDs" option to get the name of the action, but for some reason it doesn't work for this case (id of the action is not shown because of some reason). But the search via actionlist still works it you could use it.

Anyway, why wouldn't you just create a mapping to gt? Like map <leader>] gt.

0
On

Here's another way to find action names to use in IdeaVIM key bindings (or anywhere else you need the action name) by using abbreviations, if the "track action ids" does not work:

  1. Go to IntelliJ settings and open the Keymap settings.
  2. Use the search bar to find the action.
  3. Right-click (or ⌃-click) on the action and choose "Add Abbreviation".
  4. Type in a string that's unlikely to be used anywhere else. I use "zjzjzj".
  5. Click OK to close settings and save to disk.
  6. Open up your IntelliJ Configuration directory. This is idea.config.path on the page Directories used by the IDE to store settings, caches, plugins and logs. Currently on my machine it is "~/Library/Application Support/JetBrains/IntelliJIdea2023.2" but it depends on your OS and IntelliJ version.
  7. Open up the file options/abbrevs.xml in a text editor.
  8. Search for the string you used in Step 4, e.g. "zjzjzj".
  9. Now you'll see the action id you're looking for. Example below.
  10. Clean up by removing the abbreviation in Settings→Keymap.

Example of what shows up in abbrevs.xml:

      <action id="FindInPath">
        <abbreviation name="zjzjzj" />
      </action>