Introduction to the advanced use of the Vim editor in Android _android

Source: Internet
Author: User
Tags lowercase


1. Mobile Instruction
(1). h J k L, direction key, memory skills: Left and right direction is the leftmost and the rightmost, j down a tick, so is the downward key, the remaining k is the up key.
(2). b, before, Last word (first word)
W, Word, next word (first word)
E, end, next word (suffix)
Note that these lowercase commands are delimited by letters, dots, numbers, underscores, and these three corresponding uppercase letters, B,W,E, similar, but are moved by whitespace. All in all, uppercase moves in a larger range.
(3). GG First Line
G tail line, these two commands are used more
(4). n% jumps to n% 's line.
(5). ^/0 to the beginning of the line, I sometimes particularly like 0, very clear and concise command
$ to end of line
(6).-Non-blank start up move
+ non-blank start Move Down
(7). Row move


 code as follows:

NJ//Move Down n line
NK//Move up n row
NH//Left to move n columns
NL//To have move n column
N_//Move down the n-1 line, and move the cursor to the beginning of the non-whitespace
N///Move up and down, and move the cursor to the beginning of the non-blank line

(8). Move by looking up characters
 code as follows:

FX/FX//Backward/forward lookup character X, inline jump is useful
TX/TX//Backward/forward lookup character X
The difference between fx/fx and TX/TX is to stay on X with the F cursor and stay on the front of x with the T cursor.

; Perform the last FFTT
,//opposite direction to execute FFTT, these two interesting

2. Insert, replace, delete
(1). Learn A and I mix, do not only use I into the insertion mode, sometimes a into the insertion mode is more convenient, such as inserting the keyboard to the right of the letter symbol, with a, both hands together more efficient.
(2). Learn I and a, quickly enter the beginning and end of the insertion mode, a specific moment to use it super cool!
This is very good to understand, lowercase i is the cursor, the size of I is the whole line before, o/o similar, the picture is very clear.
(3). Learn O and O mix, do not only use O into the downlink edit:
(3.1). Enter the uplink editor, uppercase o faster, rather than KO, hands faster than one hand!
(3.2). When you want to insert a row before the first line, O is more direct and faster than any other operation (do not go back to the beginning <+ insert mode >+ carriage return)
(4). R Quick Substitution characters, the biggest advantage is not to switch mode, save a lot of time, very useful! (R, this command I use less, sometimes with a special confusion, do not say)
s deletes a character after the cursor and enters insert mode. This command provides a quick way to implement the R command + into the insert mode.
(5). C This command is very powerful, the description of the classification
 code as follows:

CM//m refers to the previous move command, similar to the Dm,ym,g?m,gum,gum
Change the content (m defines the scope of change) and enter the insertion mode, where the change is to delete, for example:
CW//Delete a word after the cursor and enter insert mode
CL//Delete a letter after the cursor and enter insert mode

(6). CC and S modify the current line, meaning to delete all the character contents of the line, but leave the beginning space
D and c Delete all content after the line cursor, regardless of character or space, this command I use a lot of: Code audit format code, delete blank lines of space and line trailing spaces.
(7). Learn to combine t this command
 code as follows:

T//till meaning that this is one of my favorite commands
DT "//Line Delete until", "do not delete
CT)//In-line change until), no deletion
... ...

(8). Learn x and x mixing, respectively, to delete forward and delete characters backwards
(9).: Rd Delete Line R





3. Find


 code as follows:

#//down one search result
*//down one search result
Press n/n after #/* to repeat/reverse their commands

The following two commands are useful when you are programming
GD//jump to the defined position of the cursor variable (local variable)
GD//jump to the defined position of the cursor variable (global variable)





4. Withdrawal and recovery


 code as follows:

U//Undo
CTRL + R/Recovery





5. Rolling


 code as follows:

CTRL + E/Y//down/Up line scrolling
CTRL + D/U//down/top Half page scrolling
CTRL + F/b//down/up one page scrolling





6. Visual mode (select Block)
Visual mode is actually very useful, its choice is very flexible, and the visual effect of watching and the mouse to choose the same, learning costs are low, but powerful.
(1). V into visual mode
(2). Shift + V is capital V, row selection in Visual mode, whole line selection, and is convenient for processing just the whole line or large length of content.
(3). Ctrl + V Visual mode column selection, more granular than row selection mode, you can select a continuous column entry operation
Selecting block mode requires a combination of other commands:


 code as follows:

V + G//select current line until end of text
V + G + d//delete current line until end of text
V + G + y//copy current line until end of text
V + GG + d//delete current line until beginning of text
V + GG + y//copy current line until beginning of text
Ctrl + V + < move >+ d//Delete selected columns
Ctrl + V + < move >+ y//Copy Selected columns

(4). GV Select the last selected area
(5). Select words, sentences, paragraphs:
 code as follows:

VAW//Select a word (word)
VAS//Select a sentence (sentence)
VAP//Select a paragraph (paragraph)
VIW//Select a word (word)
Vis//Select a sentence (sentence)
VIP//Select a paragraph (paragraph)

(6). Check parentheses:
code as follows:

VAB//Selection () inside the contents, including parentheses
VaB//Selection {} contents, including curly braces

7. Execute shell command
 code as follows:

Remember these two usages, you taste their sweetness.
: SH//Open shell, can execute shell command, enter exit Exit Shell return to Vim
:!cmd//Direct execution shell

For example, the automated packaging script mentioned in the previous article, I modified the code, I need to perform this script to compile, but I do not want to completely quit Vim, because I still need to continue to modify, you can use
 code as follows:

: SH//Open a terminal
./build.sh//Executive build.sh
Exit//Exit terminal, continue vim edit
Or
:!. /build.sh//Execute the build.sh script directly in the Vim window and press Enter or another command to continue

is not very convenient!





8. Topic One: Quickly select, delete, copy, change quotes or parentheses


 code as follows:

The following operations must be memorized to greatly improve the efficiency of your editing text
Ci ', Ci ', ci (, ci[, ci{, ci<///change the textual content of these paired punctuation marks, respectively)
Di ', Di ', Di (or Dib, di[, di{, or DIB, di<//delete the textual contents of these paired punctuation marks, respectively)
Yi ', Yi ', Yi (, yi[, yi{, yi<///Copy the textual content of these paired punctuation marks, respectively)
VI ', VI ', VI (, vi[, vi{, vi<///Select the textual content of these paired punctuation marks, respectively

9. Topic II: Replacement
Find and replace operations are used too frequently, and there are several common and powerful uses of substitution from the Internet or books for this topic:
 code as follows:

Grammar
/**
* Description
* Range indicates the number of rows, if% represents all rows
* s denotes substitution, substitution meaning
* Flag indicating mark, value g,i,c, etc.
* g means global, all
* I denotes ignore, ignoring case
* C means confirm, one interactive confirmation replacement
* Count indicates the range from the current line to the next line
*/
: [Range]s/{pattern}/{string}/[flag] [count]

(1). Replace All
The parameter G implements all substitutions, otherwise it replaces only one
(1). Replace All
The parameter G implements all substitutions, otherwise it replaces only one

:%s/{old-pattern}/new-text/g





(2). In-line substitution
% represents all rows, minus% represents current line, only replaces when forward

: s/{old-pattern}/new-text/g



(3). Specify row range substitution
Replace results for 1 to 10 rows

: 1,10s/{old-pattern}/new-text/g



(4). Visual Mode substitution
If you think the number of rows is more troublesome, you can use Visual mode, first enter the visual mode, and then select the row
column, and finally enter: Auto Enter: ';, ' >
followed by s/{old-pattern}/new-text/g, only the result of the selection is replaced

: ';, ' >s/{old-pattern}/new-text/g



(5). Replacement of whole words, not partially matched words
Outsource a < and > to a word matching pattern

: s/\<blog\>/weibo/g//Replace blog, but Cnblog,blogs will not replace



(6). Multiple replacement
Substitute a string for more than one match at a time

:%s/\ (good\|nice\)/awesome/g//good and Nice will be replaced by awesome



(7). Confirm-Type replacement
The parameter C lets the substitution make the interaction request, needs you to choose Y,n,a,l,q


 code as follows:

/**
* Select Description:
* y substitution and jump to next match result
* N does not replace and jumps to the next matching result
* A replaces all and exits the interactive mode
* L Replace current and exit interactive mode
* Q Exit Interactive mode
*/
: S/{OLD-PATTERN}/NEW-TEXT/GC

(8). Inserts the line number at the beginning
To replace the line number with the beginning of the line, you can customize the specific form
:%s/^/\=line (".") /g





10. Topic Three: Case-by-case conversion
Speaking of this, the main thing is that the problem is very interesting.


 code as follows:

~//Change the current character and automatically switch to the next character, uppercase to lowercase, lowercase to uppercase, you can always press
Gum//converted to lowercase, m refers to the move command, such as:
Guw A word after the cursor is lowercase
GUG the line to the last line of the cursor all lowercase
Gut= the characters after the cursor until = lowercase
Gu can also be combined with visual mode to lower the selected area
GUm//conversion to uppercase, usage ibid.

11. Topic IV: Recording
This is actually very simple, but also very powerful function, separate Eurya out for a moment.
 code as follows:

Define macros or aliases for actions
The strength of this command is that it simplifies the repetition of complex instructions.
Q//press Q to start recording
X//x is the register of this recording, x can be other characters
DD//Delete current line, this operation can customize other complex operations
Q//recording ended, now DD This operation is defined in the @x command.





12. Topic V: Increase or decrease in numbers
This tip is useful, for example, to define a series of static final variables, and occasionally insert new variables in the middle, which are generally incremented, and this technique is definitely more convenient than the replacement of numbers.


 code as follows:

Execute in Normal mode
Ctrl + A//self increase 1
Ctrl + x//self minus 1

13. Summary
The work of good things, the first benefit of its device.
Think of these first, there must be a lot of omissions, behind the thought of what I will always add updates to come in.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.