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

How to acquire seed users without money or resources?

When a new product is just starting to operate, I...

The women and men behind Jack Ma

Alibaba's brilliant victory on Double 11 once...

What is the difference between Baidu and Google?

Recently, Baidu CEO Robin Li personally answered ...

How to choose the right package when applying for 400 phone number?

The application for a 400 telephone number is inc...

Source Code|Cloud Tags

Source code introduction: cloud tag deletion, add...

Mango TV officially starts its VR journey with Super Girl

Nowadays, it is no longer a new thing for an Inte...

Channel operation: How can newcomers do a good job in app store promotion?

1 What is channel operation promotion The term &q...

Musk's chopsticks "grip" the rocket: a space version of a claw machine

You know about claw machines, right? You put in c...

Which Baidu Aicaigou platform performs well?

As one of the largest search engines, Baidu has a...

How to plan a successful event promotion?

I believe everyone is familiar with event promoti...

Does it really help to lie down with your eyes closed when you can't sleep?

Addendum 1: Although lying down with your eyes cl...

The most comprehensive big data analysis report on Double Eleven 2017!

So today, I will take you to explore the secrets ...

Tesla's global Internet outage paralyzed its cars, netizens: nothing new

Tesla’s Battery Day had just ended when tragedy s...