Speed up your code editing with Vim emulation in Android Studio

Dmytro Ostrovskyi
Appus Studio
Published in
4 min readFeb 17, 2021

--

Why?

Every successful IT company needs productive developers to make the job done as quickly as possible and deliver awesome products for customers. But what helps programmers to write code fast? I believe there are two main characteristics:

  • deep knowledge of tech stack
  • efficient using of tools

Let’s talk about tools for now. As Android Developer I use Android Studio every day, and it’s an awesome tool to work with all needed IDE futures, but it’s hard to edit code without a mouse there.

One of the main variants for mouseless text editing is Vim, where you can navigate through code using keys that are already under your fingers. It saves a ton of time. The main argument for Vim is its high-speed editing power. It allows you to edit text intuitively and powerfully. Vim contains many functionalities. Every day I use Vim I learn something new or read about a new feature I never heard of before.

For Android Studio it is called “IdeaVim” and with this plugin, you can write your code completely without a mouse. Cool, right?

How to use it?

So… How does IdeaVim work exactly? There are 3 main modes.

  • Normal (or command) mode, where you navigate and edit.
  • Insert, where you write new text.
  • Visual, where you’re selecting text.

By default, you are in Normal mode.
If you need to write something, just press i (insert mode) and type. To go back to normal mode press ESC.

Moving Around

Here are some basic bindings for moving around.

Left → h

Right → l

Up → k

Down → j

Jump forward to the Start of word → w

Jump forward to the End of word → e

Jump backward to the Start of word → b

Jump to the Start of line → 0 (zero)

Jump to the first character of line → ^

Jump to the End of line → $

Append to the Start of the line → I

Append to the End of line → A

Next instance of the current word → *

The previous instance of the current word → #

The first line of file → gg

Last line of file → G

Top of the screen → H

Middle of the screen → M

Bottom of the screen → L

There are more commands for moving, you can check out them here.

Editing

Replace single character → r

Change entire line → cc

Change word (onwards from cursor) → cw

Change entire word → ciw

Change till end of line → c$

Change case → ~

Change till next character e.g. ‘i’ → cti

Change till next character e.g. ‘i’ (inclusive) → cfi

Copy/Cut/Paste

Paste → p

Paste before the cursor → P

Copy entire line → yy

Copy a word → yiw

Cut entire line → dd

Cut a word → diw

Vim stores the copy/cut history in the register. You can access it by :reg command. Select the register with the prefix “ and paste text from there.

Search and Replace

Search for pattern → /pattern

Search backwards for pattern → ?pattern

Repeat search in the same direction → n

Repeat search in the opposite direction → N

Replace all old patterns with new → %s/oldPattern/newPattern/g

Replace old patterns with new (ask) → %s/oldPattern/newPattern/gc

Selecting Text

Visual Mode → v

In visual mode all moving commands are works. For example, you can press w and select a word.

Conclusion

IdeaVim is a really powerful plugin for Android Studio, and now you know basic stuff. Mastering Vim functionality will improve your productivity. Using Vim you can perform many complex tasks with few keystrokes under your fingertips. You can check the following resources to learn more about Vim.

Resources

Official documentation for vim

IdeaVim GitHub page
Awesome vim cheat sheet

--

--