How to use Vim on Android to improve development efficiency

How to use Vim on Android to improve development efficiency

background

Although I am an Android development engineer, I have also come into contact with various IDEs (not limited to Android development). Different IDEs often have different shortcut keys, and we can't configure every IDE. In fact, most IDEs now support Vim in the form of plug-ins. Therefore, you only need to master the basic use of Vim, and you can quickly get started in IDEs that support Vim, with familiar operations and familiar feel.

Vim Mode

Vim can be divided into 3 modes: Normal mode, Visual mode and Insert mode. The following basic operations are all performed in Normal mode. The differences between the three modes are not explained in detail here. Bing search has many related basic tutorials.

The relationship between the three can be simply described by the following figure

Basic Operation

Cursor Movement

Pay attention to the difference between uppercase and lowercase letters

Up, down, left, right

Just look at the table, it's simple and easy to understand. It may be a little awkward at first, but you will love it after getting used to it.

k (up)
h (left) l (right)
j (down)

Inter-word positioning

Key position

If capitalized, words are allowed to contain punctuation

w (jump forward to the beginning of a word)

e (jump forward to the end of the word)

b (jump back to the beginning of a word)

Inline positioning

Key position

$ (position to the end of the line)

0 (position to the beginning of the line)

^ (position to the beginning of the line, ignoring spaces)

f

Forward search for the character ch. If ch is a letter, it is case-sensitive.

F Reverse search for the character ch. If ch is a letter, it is case-sensitive.

Block positioning

Key position

{(jump to the previous code block)

} (jump to the next code block)

% (positions to another matching bracket)

Page Positioning

Key position

gg (position to the first line of the page) G (position to the last line of the page) H (position to the top of the current page, High is capitalized) M (position to the middle of the current page, Middle is capitalized) L (position to the bottom of the current page, Low is capitalized)
nG or ngg (position to the specified line, n represents the line number, must be greater than 0, if it is greater than the *** line number, it will jump directly to the *** line of the page)
m and ' (this is a very powerful pair of commands that can mark a location and then quickly locate the mark on the same page. m means mark, a is a letter, which can be one of the 26 letters, and ' is a single quote followed by the previously marked letter)

Screen scrolling

Full screen scrolling

Key position

Ctrl + f (scroll down one screen, the first letter of Foward is lowercase)

Ctrl + b (scroll up one screen, Backward has a lowercase first letter)

Half screen scroll

Key position

Ctrl + d (scroll down half a screen, Down is lowercase)

Ctrl + u (scroll up half a screen, Up is lowercase)

Line Scrolling

Key position

Ctrl + e (scroll down one line)

Ctrl + y (scroll up one line)

Edit Mode

insert

Key position

i (insert at the cursor, the first letter of insert is lowercase)

I (insert at the beginning of the line, the first letter of insert is capitalized)

a (insert the character after the cursor, the first letter of append is lowercase)

A (insert at the end of the line, the first letter of append is capitalized)

o (insert in the previous row)

O (Insert at the next row)

cc/S (clear the current line and enter insert mode)

s (clear the current character and enter insert mode)

Well, this is very simple, so I won’t post a picture.

Find

Key position

/pattern (forward search)

?pattern (reverse lookup)

n (find next)

N (Find Previous)

* (When the cursor is on a word, search for the next word)

# (When the cursor is on a word, search for the previous word)

replace

Key position

:%s/old/new/g (globally replace old with new)

:s/old/new/g (replace the current line old with new)

Note that the replace operation is only effective on the current page, so use this operation with caution.
It is recommended to use the IDE's built-in renaming operation, which can also rename the corresponding references!

Cut, Copy, Paste

Key position

dd (cut the contents of the current line)

D (cut the content from the cursor to the end of the line)

yy/Y (copy the contents of the current line)

p (paste after cursor)

P (paste before the cursor)

Revocation

Key position

u (undo the previous step, IDE usually uses Cmd + Z)

This is simple and no need to post pictures.

Combination Operations

Combination operations can be seen as the application of the formula op+i/a+scope. To explain this formula, op is the insert (c), cut (d), copy (y) and select (v) mentioned earlier, i means within the scope, a means including the scope tag, and scope is the scope of the operation. This is a bit abstract, so here are some common combinations.

Select text

Key position

If i is replaced with a below, the symbol will also be included

vib (select the content in parentheses)

viB (select the content within the curly brackets)

vi" (select the content within double quotes)

vi' (select the content within single quotes)

vi< (select the content in the angle brackets)

Similarly, replacing the selection operation (v) with insert (c), cut (d) or copy (y) can achieve a similar effect.

Magical Operation

IDE supports jumping to the definition or call of variables (methods). Vim also supports this function, which is also very convenient. Just position the cursor on the method name and enter gd. With Android Studio's Navigate Back, you can easily view the method calls.

Navigate Back Settings

Fragments

Once you have mastered Vim, if you use a new IDE or development environment in the future, as long as it supports Vim, you can quickly become familiar with the development environment. Of course, many IDEs provide more complete shortcut keys. The author's point of view is that Vim and IDE are used together to complement each other's shortcomings.

Reference Links

  • https://jasonliao.me/posts/2016-08-09-you-dont-know-vim.html

  • https://vim.rtorr.com/lang/zh_cn/

<<:  Modify the default font globally, which can also be done through reflection

>>:  Apple acquires French image recognition company, may embed technology into iPhone

Recommend

Tips to increase your Facebook page to tens of thousands of fans!

As the largest overseas social platform, Facebook...

How to correctly place information flow ads?

Information flow advertising is now the new favor...

The most comprehensive guide to Weibo Fanstong advertising

Weibo's "Fanstong" is a marketing p...

What are the advantages of news app development?

In this era of information explosion, are you sti...

"Wi-Fi.HK" free wireless network throughout Hong Kong

This year, the Hong Kong government will work with...

Douyin operates traffic, increases fans and conversions!

I believe that for the vast majority of companies...

Example Analysis | How to do marketing promotion?

After reading more than 30 marketing proposals ma...

How to operate content well and create phenomenal products

In my past work experience, I have always been th...

Help! Why is someone feeding meat to Rose?

The editor sent me a picture, and my fruit flies ...

The first great ape named by the Chinese, fewer than 150 of them are still alive

The Tianxing gibbon was officially named by Chine...

Are frost and frost the same thing? Here are 7 tips to deal with frost!

Today is Frost Descent, the eighteenth of the twe...

Alfa Romeo Stelvio has been declared as a competitor to Macan

When it comes to Alfa Romeo, everyone will think ...