Vim's vertical editing mode is powerful. This article introduces the Vim vertical editing mode and the application of the VisIncr plug-in the development and testing scenarios, so that readers can more intuitively understand the Vim vertical editing mode function.
Before getting started
The human brain processes text in a flat manner. Therefore, we can browse articles, search for materials, or reconstruct code by either reading horizontally or reading vertically or using the search function, take the text as a plane. When editing text and writing code, it is either horizontal or vertical. Regular text editors are both horizontally edited, and vertical editing is often used as a special feature. For example, Vim, EditPlus, and UltraEdit editors all have vertical editing mode, or column mode. MicroSoft Word and OpenOffice Writer can also press the function key ALT to select text vertically and operate the text. Vertical editing is not only a function of the editor, but also a way for people to think about problems. The project symbols and paragraph numbers are the embodiment of vertical editing.
The vertical editing mode of Vim is easy to start and flexible to use. It can also be used with the plug-in to implement very useful advanced functions.
Start Method
In Vim command mode, move the cursor to a certain position, type ctrl-v, and the visual block appears on the status bar to enter the vertical editing mode. Move the cursor to select the region to be edited as needed. Note: In Windows Vim, the ctrl-v key combination is usually mapped to text paste, so the vertical editing mode of Vim in Windows is started by ctrl-q. Of course, the flexible Vim can also be customized by the user.
Example 1: application demonstration of vertical editing in batch code modification
Series:
10.1.5.21410.1.5.21210.1.5.210
Edit to sequence:
ping -c 4 10.5.5.214 >> result0ping -c 4 10.5.5.212 >> result0ping -c 4 10.5.5.210 >> result0
This is a process of modifying the IP sequence to an executable ping command sequence.
Step 1: Modify
Change the number "1" in the second segment of the IP series to "5 ":
Position the cursor to the "1" in the second segment of the IP address in the first line"
Ctrl-v enter vertical editing mode
G move the cursor to the last row. The visible block overwrites the column to be modified.
R enters the modification mode.
5. Enter the number "5"
ESC exits the vertical editing mode, and all selected numbers are changed to "5", and return to the command mode.
The result is as follows:
10.5.5.21410.5.5.21210.5.5.210
Step 2: add
Add "ping-c 4" before all rows ":
Move the cursor to the first column of the First row
Ctrl-v enter vertical editing mode
G moves the cursor to the first column of the last row. The visible block overwrites the first column.
I. Enter the first row insert mode.
Ping-c 4 enter the required character "ping-c 4"
When ESC exits the vertical editing mode, "ping-c 4" is added before all selected characters to return to the command mode.
The result is as follows:
ping -c 4 10.5.5.214ping -c 4 10.5.5.212ping -c 4 10.5.5.210
Step 3: add
Add "> result0" after all rows ":
Move the cursor to the last column of the first row
Ctrl-v enter vertical editing mode
G moves the cursor to the last column of the last row. visual block overwrites the last column.
A enters the row-end insertion mode.
> Result: Enter the required character "> result0"
When ESC exits the vertical editing mode and all selected characters are added with "> result0", return to the command mode.
The result is as follows:
ping -c 4 10.5.5.214 >> result0ping -c 4 10.5.5.212 >> result0ping -c 4 10.5.5.210 >> result0
The preceding three steps share a common feature, that is, they all adopt vertical editing directions. The above three lines of code can also be applied to more lines.
Install and operate VisIncr
In the preceding example, the vertical editing of the code can also be achieved through the Common Code reconstruction function or the search and replacement with a regular expression. However, Vim's vertical editing mode can also be expanded by the VisIncr plug-in to implement richer functions, such as vertical generation of series.
Search for the VisIncr plugin installation file from the Vim official website and download it to the Vim working directory. Run the following command to install the plug-in:
vim visincr.vba.gz:so %:q
The procedure is as follows:
Use ctrl-v and move the cursor to select a column with the last digit "0"
: Type A colon to trigger Vim to enter the command line mode.
: I starts with the first number and generates an incremental series vertically. The range is 1.
ENTER, type the drive key, and run the command.
The result is as follows:
ping -c 4 10.5.5.214 >> result0ping -c 4 10.5.5.212 >> result1ping -c 4 10.5.5.210 >> result2
Example 2: application demonstration of VisIncr in generating test data
During application development, a simple and regular test data is often generated. For example, for a table:
testTable (”ipaddr” ,”filename”, ”owner”)
Generate the following SQL statement:
insert into test values("10.5.5.214”,”result0”,”testa”);insert into test values(”10.5.5.212”,”result1”,”testb”);insert into test values(”10.5.5.210”,”result2”,”testc”);
This vertical and regular statement sequence can be constructed using the vertical editing function of VinIncr.
Step 1: Prepare
Open a new Vim editing page, enter "3" in command mode, and then enter "I" to enter the editing mode. The number "3" indicates that the entered content will be repeated three times.
Enter the first line in VIM:
insert into test values(”10.5.5.214”,”result0”,”testa”);
Press enter to end the line and enter a new line. Press ESC to exit the editing mode.
If:
insert into test values(”10.5.5.214”,”result0”,”testa”);insert into test values(”10.5.5.214”,”result0”,”testa”);insert into test values(”10.5.5.214”,”result0”,”testa”);
Step 2: Construct a descending sequence
For the ipaddr column, use ctrl-v and move the cursor to select the area where the last segment of the IP address decreases by 2:
: Type A colon to trigger Vim to enter the command line mode.
: I-2 uses the first number as the starting point to generate a descending series vertically with a range of 2
ENTER, type the drive key, and run the command.
The result is as follows:
insert into test values(”10.5.5.214”,”result0”,”testa”);insert into test values(”10.5.5.212”,”result0”,”testa”);insert into test values(”10.5.5.210”,”result0”,”testa”);
Step 3: Construct an incremental series
For the filename column, use the method described in the previous section. The result is as follows:
insert into test values(”10.5.5.214”,”result0”,”testa”);insert into test values(”10.5.5.212”,”result1”,”testa”);insert into test values(”10.5.5.210”,”result2”,”testa”);
Step 4: Create an ascending letter Series
For the owner column, use ctrl-v and move the cursor to select the part where the English letters will increase progressively.
: Type A colon to trigger Vim to enter the command line mode.
: IA uses the first letter as the starting point to generate a sequence in alphabetical order vertically.
ENTER, type the ENTER key, and run the command.
The result is as follows:
insert into test values(”10.5.5.214”,”result0”,”testa”);insert into test values(”10.5.5.212”,”result1”,”testb”);insert into test values(”10.5.5.210”,”result2”,”testc”);
The preceding steps demonstrate how to use the Vim plug-in VisIncr to vertically edit the code and generate a series with regular logic in the vertical direction.
Summary
Vim is not only an editing tool, but also a set of thinking methods. Vim has a lot of skills to guide the way of thinking, so that Vim remains New when the various editors emerge one after another. This article uses vertical editing as the starting point and uses VisIncr to demonstrate examples that can be used during development and testing.