Phpstorm Vim



Japanese version is here

I’m looking for comprehensive list of keys bindings for IdeaVim (vim emulator for PhpStorm and stuff like that). It looks like this plugin has lots of useful key binding which don’t exist in vim and aren’t standard. I have been trying to switch to Vim from PhpStorm for web development (PHP (laravel, wordpress, custom cms), Javascript (vanilla and VueJS), CSS, HTML) and I'm having a hard time with certain aspects; I'm wondering if some of you could suggest me some plugins, worflow or insights on how to better my Vim game. Vim emulation plugin for IntelliJ Platform-based IDEs. IdeaVim supports many Vim features including normal/insert/visual modes, motion keys, deletion/changing, marks, registers, some Ex commands, Vim regexps, configuration via /.ideavimrc, macros, Vim plugins, etc. See also: GitHub repository: documentation and contributing.

  • Vim PhpStorm RubyMine WebStorm Jupyter. Emacs GoLand Clion Android Studio.
  • Restart PhpStorm. Turn on the plugin via checking ‘Tools’ then ‘Vim Emulator’. Original PhpStorm shortcuts and Vim shortcuts (enabled by the plugin) can conflict with each other, so you need to resolve these conflicts manually. Navigate to ‘File’, ‘Settings’, ‘Other Settings’, then ‘Vim Emulation’.

IdeaVim

IdeaVimGithub: JetBrains/ideavim

IdeaVim is a Vim emulation plugin for IntelliJ or other Jetbrains IDEs. This plugin are officially developed by Jetbrains as you can see the repository owner name.

Demo

Keymap is personally customized.

Why use IdeaVim

The advantages in each of IntelliJ and Vim are as follows, I think.

  • IntelliJ: Very powerful code completeion, code navigation, refactoring, and so on with easy and simple settings.
  • Vim: Very various and efficient operations as a text editor. A concept of the mode(normal/insert/visual).

So, IntelliJ with Vim-like operation can take both of these advantages. IdeaVim supports many Vim features.

In this blog post, I'll introduce what features IdeaVim supports, how to setup IdeaVim, and how great IdeaVim is.

Supported Vim features

The followings are commonly used Vim features supported by IdeaVim.

FeatureSupported
ModeNORMAL, INSERT and VISUAL mode
Motionsyank(y), delete(d), change(c), undo(u), redo(Ctrl-r),
text object operation(ciw,ci', ... ) and so on
Searchtextsearch and highlight by /, incremental search by :set incsearch
Replace:s,:%s,:'<,'>s and so on
Commands:w, :q, :tabnew, :split, a part of :set command and so on
KeymapWe can customize keymaps by same syntax with .vimrc. We can use map, set and other some commands. The details of this feature will be introduced later of this blog post.
Macroavailable
Registeravailable
Others:set surround enables vim-surround emulation

You can see more details at README.md of GitHub repositoy.

Install IdeaVim

In IntelliJ or other Jetbrains IDEs, you can install IdeaVim from [Preferences] > [Plugins].After install, you have to restart the IDE to enable IdeaVim.

EAP build

You can install an EAP (Early Access Program) build of IdeaVim by adding the following URL to [Settings] > [Plugins] > [Browse Repositories] > [Manage Repositories].

Currently, a new version of IdeaVim is officially released a few times for a year, so sometimes bug fixes or new features are not released soon. So I normally use the EAP build.

How to setup IdeaVim

.ideavimrc

IdeaVim loads a file ~/.ideavimrc when the IDE started. We can write the settings to .ideavimrc, with the same syntax as .vimrc. A list of supported set commands is here.
In addition, a set surround command enables a vim-surround emulation.

Share the keymaps between Vim and IdeaVim

VimVim

.vimrc and .ideavimrc can be written as the same syntax. This is a large advantage, because you don't need to learn new specific syntax, and you can share the settings of the common basic keymaps (e.g. nnoremap ; :) between both of them.

To share the settings, I prepared a shared keymaps file .vimrc.keymap. It is loaded in .vimrc and .ideavimrc by a source command. Thus you can centralize the common basic keymaps to the one file.

.ideavimrc

.vimrc.keymap

The followngs are my .ideavimrc and .vimrc.keymap.

Exit vim

Vim-like keymap to IntelliJ functions

In my .ideavimrc, a statement map XXX :action YYY often appears. :action is a IdeaVim-specific command. By using :action command, you can call IntelliJ functions.

The following is an example of keymap.

Exit vim

GotoDeclaration is one of an 'action'. An action corresponds to one of the IntelliJ functions. It navigates to the declaration of the symbol on the text cursor. So, nnoremap gd :action GotoDeclaration means, 'When you type gd in the normal mode, then you'll be navigated to the declaration of the symbol'.
Thus, by using an :action command, you can define a vim-like keymap to any IntelliJ functions, even very powerful code modification, code navigation, refactoring, and the more functions.

You can call any IntelliJ functions, from high-level functions (e.g. refactoring) to low-level functions (e.g. move text cursor). You can also call the functions of the IntelliJ plugin you've installed.

The :action command dramatically boosts the usability of IdeaVim-ed IntelliJ.
The followings are my recommended actions.

Examples of Action

ActionDescription
SearchEverywhereNavigate to any symbol
FindInPathFind text in the whole project
FileStructurePopupNavigate to any symbol in current file
GotoDeclarationNavigate to the declaration of a symbol
GotoSuperMethodNavigate to the super method of a symbol
GotoImplementationNavigate to the implementation of an interface
JumpToLastChangeNavigate to the place changed at last
FindUsagesList the usages of a symbol
RenameElementRename a symbol
ReformatCodeFormat code
CommentByLineCommentComment out
ShowIntentionActionsQuick fix
GotoActionCall anything
Phpstorm Vim

An example

Search an action name

If you want to know an action name of some IntelliJ functions, you can use an :actionlist command.By using the command you can search an action by words.

Gvim Windows 10

But, currently there is no way to know the action name of the IntelliJ function which you want to call from IdeaVim.
Calling :actionlist will display assigned shortcut key for the each action. It may be a hint of the corresponded IntelliJ function.

Conclusion

Phpstorm Vim キーバインド

In this blog post, I introduced IdeaVim. IdeaVim hasn't emulated Vim completely yet, but it's still a great plugin.
Let's enjoy IdeaVim!