Vim in IntelliJ and other JetBrains IDEs: IdeaVim setup
Install IdeaVim from Settings › Plugins, restart, and every JetBrains IDE (IntelliJ IDEA, PyCharm, WebStorm, GoLand, Rider, Android Studio and the rest) edits like Vim. Configure it in ~/.ideavimrc, which reads like a .vimrc: set a leader, turn on emulated plugins such as surround and commentary, and map keys to IDE actions with <Action>(...). Settle shortcut clashes in Settings › Editor › Vim.
| Line | What it does |
|---|---|
let mapleader=" " | Makes ␣ your leader key; put it before mappings that use <leader> |
set clipboard+=unnamed | Yank and put use the system clipboard (the * register) |
set clipboard+=ideaput | Puts go through the IDE's own paste, so pasted code is handled as the IDE would |
set ideajoin | J uses the IDE's smart join instead of Vim's |
set idearefactormode=keep | Stays in the current mode when a refactoring selects text |
set surround | Emulated vim-surround: ys, cs, ds |
set commentary | Emulated vim-commentary: gcc, gc |
set highlightedyank | Briefly highlights what you yanked |
map <leader>r <Action>(RenameElement) | Space r runs the IDE's Rename refactoring |
map gh <Action>(ShowErrorDescription) | Shows the error under the cursor, without the mouse |
Install IdeaVim
- Open Settings › Plugins, search the Marketplace for IdeaVim, install it, and restart the IDE.
- Tools › Vim in the main menu turns it on and off, which is handy when you pair with someone who doesn't use Vim.
- An IdeaVim widget appears in the status bar. Use it to Create ~/.ideavimrc; the file opens in the editor, and the widget gives you quick access to it later.
The same plugin works in IntelliJ IDEA, PyCharm, GoLand, CLion, PhpStorm, WebStorm, RubyMine, DataGrip, DataSpell, Rider, Android Studio and other JetBrains IDEs, and one ~/.ideavimrc serves them all.
Your ~/.ideavimrc
IdeaVim reads ~/.ideavimrc when the IDE starts. If you prefer XDG paths, it also reads $XDG_CONFIG_HOME/ideavim/ideavimrc. The syntax is Vim's, so the table above can go in as it is, one setting per line.
After editing it, reload it: the JetBrains docs say to press Ctrl+Shift+O.
Already have a .vimrc? Put source ~/.vimrc at the top of ~/.ideavimrc and add IDE-only lines below it. Keep in mind that IdeaVim runs Vim script but doesn't support every built-in function and option, and Vim plugins installed in your .vimrc won't load. If one config serves both, wrap IDE-only lines in if has('ide') ... endif; has('ide') is 1 in IdeaVim and 0 in Vim or Neovim.
A few more IdeaVim-only options worth knowing:
set ideamarkskeeps the IDE's bookmarks in sync with Vim's global marks (capital letters only).set ideastatusicon=gray(ordisabled) tones down the status bar icon.set ideawrite=allmakes:wsave all files, like the IDE's Save All.
Map keys to IDE actions
The best part of IdeaVim is driving the IDE from Normal mode. Every menu item and refactoring is an action with an ID, and you map to it with <Action>(ID):
map <leader>r <Action>(RenameElement)map <leader>f <Action>(GotoFile)map <leader>g <Action>(FindInPath)map <leader>b <Action>(ToggleLineBreakpoint)map <leader>o <Action>(FileStructurePopup)map \r <Action>(ReformatCode)
Two rules from the IdeaVim docs: don't forget the parentheses, and use `map`, not `noremap`, because mappings to <Action> don't work with noremap. To run an action once from the command line, type :action ReformatCode, but don't use :action inside mappings.
Finding action IDs:
:actionlistwith a pattern searches by ID or by shortcut, for example:actionlist extractor:actionlist <C-D.- Run IdeaVim: track action IDs from Search Everywhere (press Shift twice). From then on, every action you trigger with the mouse or a shortcut shows its ID in a notification. Click the menu item you want, copy the ID, and map it.
Shortcut conflicts
Many IDE shortcuts are also Vim commands: Ctrl-v (Visual block or paste?), Ctrl-r (redo or run?), Ctrl-d, Ctrl-w and more. When you press one that hasn't been decided yet, IdeaVim shows a popup offering to settle it.
To decide them all at once, open Settings › Editor › Vim (on macOS, Preferences › Editor › Vim). Each shortcut IdeaVim knows about has a handler you can set to IDE, Vim, or Undefined, which keeps asking. A sensible start:
- Vim: Ctrl-v, Ctrl-r, Ctrl-o, Ctrl-i, Ctrl-d, Ctrl-u, Ctrl-w (window commands).
- IDE: the ones you rely on in the IDE and don't use in Vim, such as Ctrl+Shift combinations.
You can also change the IDE side in Settings › Keymap, or remap the key in ~/.ideavimrc to an action of your choice.
The keys worth giving to Vim
Each of these is a Ctrl key (or a join) that the IDE also wants. Type the Vim keys from memory, then set the ones you use to Vim in Settings › Editor › Vim.
Emulated plugins
IdeaVim can't load real Vim plugins, but it ships its own versions of many popular ones. Turn each on with a set line (the docs also accept the familiar Plug 'tpope/vim-surround' form):
set surround(vim-surround),set commentary(vim-commentary),set exchange,set ReplaceWithRegister- Text objects:
set argtextobj(function arguments),set textobj-entire(the whole file),set textobj-indent(indent levels; note the name),set targets - Motion helpers:
set easymotion,set quickscope,set matchit,set CamelCaseMotion - Other:
set highlightedyank,set multiple-cursors,set NERDTree(a file tree),set which-key(shows the keys you can press next)
Some need a companion plugin from the Marketplace: easymotion needs IdeaVim-EasyMotion and AceJump, quick-scope needs IdeaVim-Quickscope, and which-key needs the Which-Key plugin. The IdeaVim Plugins page in the project wiki lists all of them with their exact names.
The motions are the same as in Vim, and the course teaches them in a real editor in the browser.
Warm up: set commentary, and a dot that repeats it
With set commentary in your ~/.ideavimrc, gcc comments a line in the IDE just as it does here, and . repeats it. Change the argument with ci(, comment out the first log line with gcc, then the second with j ..
Stuck? Show the keys
Withset surround, ys, cs and ds work in the IDE too: yst;) wraps everything up to the semicolon in brackets. Those are a plugin's keys rather than Vim's, so try them in the IDE itself.This editor needs a keyboard. Read on, and play it at your computer.
Questions
- Where is the IdeaVim config file?
-
~/.ideavimrcin your home folder, or$XDG_CONFIG_HOME/ideavim/ideavimrc. Create it from the IdeaVim widget in the status bar if it doesn't exist. - How do I make IdeaVim use the system clipboard?
- Add
set clipboard+=unnamedto~/.ideavimrc. Addset clipboard+=ideaputtoo if you want puts to go through the IDE's own paste. - Why does my <Action> mapping do nothing?
- Check that it uses
maprather thannoremap, that the parentheses are there, and that the action ID is exact.:actionlistwith part of the name finds the right ID.