Some useful commands in VIM

Source: Internet
Author: User
The purpose of this article is to summarize some practical and regular Vim commands in daily operations, instead of introducing some basic Vim knowledge, such as several insert modes, hjkl mobile commands, and DD to delete this line, P paste and so on. For more information about vim, see other tutorials. In addition, we strongly recommend a powerful Vim plug-in set" Spf13-vim", This is a Vim plug-in set, which combines some commonly used Vim plug-ins to meet the needs of most people, out-of-the-box, instead of having to configure the vim plug-in one by one, handle various key conflicts and so on, eliminating the need to spend a lot of time configuring the vim software itself (for example, when the blogger first learned Vim), rather than using Vim to better solve the problem. Finally, this blog post will be updated from time to time ....
Command 1: [vydc] [Ia] [pair_char]The preceding command indicates that the command consists of three parts, each of which can be any character in []. The first part specifies the "Operation Type" The second and third parts specify the "Operation Range" based on the current cursor position, which is very important.(1) V: Visual selecty: copyd: deletec: change. The difference between it and delete is that it first deletes and then enters "insert mode "; it is equivalent to D and then press I to enter "insert mode" (2) pair_char can be paired characters, such as {[(<"', you can also use their corresponding right close version, for example,}] and so on. pair_char can be W, which indicates the word where the cursor is located (separated by spaces). In this case, is I or a used in the middle, the difference is that the operation result package does not contain spaces (3) I: exclude the pair_chara: the difference between include the pair_chari and A is that the specified "Operation Range" package does not include this pair of characters specified by pair_char, that is, {}, [], (), or "". For example:Assume there is a text behavior ABCD "fgh ijk <lmn>"; the cursor is at M (underline) VI <Purpose: Select lmn Ya"Role: copied "fgh ijk <lmn>" Di"Purpose: delete fgh ijk <lmn> CI <Purpose: delete lmn and enter "insert mode". The cursor is located in the middle of <>   Command 2: [vydc] [TF] [a_char](1) See (1) (2) T: Till, exclude the character 'A _ char 'f: find, include the character 'A _ char't and F represent from left to right. You can also use uppercase T and F to represent a character from right to left (3) a_char, in special cases, values 0 and $ indicate the beginning and end of a row.   Command 3: Convert case to Gu, Gu(1) [visual_select_something_by_someway] Gu [visual_select_something_by_someway] Gu selects the content of a range in some way (you can select the content by using the V command in command 1 and 2 ), then convert it to uppercase or lowercase (2) gu [Ia] [pair_char] Gu [Ia] [pair_char] Gu [TF] [a_char] Gu [TF] [a_char] in this way, you must specify through Gu to convert to uppercase and lowercase, then, specify the "Operation Range" through the last two parts [Ia] [pair_char]. For more information, see the interpretation of command 1. Here, I or a is used in the middle part. It seems that there is no difference. [TF] [a_char] refer command 2   Command 4: macro commandThe recording command Qa [do_some_routine_job_in_this_line_and_move_to_next_line] Q executes the recording command in the previous step [N] @ a qa. A indicates the register in which the recording command is stored, corresponds to a in [N] @. Therefore, a can also be changed to B, c, d... N in [N] @ A represents the number of times the recording command was executed. If n is omitted, the macro command is executed once. It is very suitable for executing operations that are regular for each row, first, press QA to enter the recording mode, then perform regular operations on the row in the first line, move to the next line, and press a to exit the recording mode, use [N] @ A to batch process all the remaining rows. Assume that there are the following lines of text, and each line represents a user name. Now you need to reset the password to 123456 for this user name, for simplicity, assume there are only five rows:
user1user2user3user4user5

Place the cursor somewhere in the first line. In "Normal Mode" mode, qaialter user_table SET Password = '000000' where username = '<ESC> a' in sequence '; <ESC> ja

Okay. After the recording command is complete, run [email protected] to process the remaining four rows as the same result as the first line.

The execution result is as follows:
alter user_table set password=‘123456‘ where username=‘user1‘;alter user_table set password=‘123456‘ where username=‘user2‘;alter user_table set password=‘123456‘ where username=‘user3‘;alter user_table set password=‘123456‘ where username=‘user4‘;alter user_table set password=‘123456‘ where username=‘user5‘;
    Command 5: code auto indent =(1) move the cursor to a certain position, and then use VI {to select the code block {code} to be automatically scaled down. Finally, press = (2) and press uppercase V to enter the row selection mode, use JK to move up and down to select the row set to be automatically scaled down. Finally, press = (3) to the lazy method, GG to the first line, VG to select all rows of the file, and finally, press = to format all codes   Command 6: Invert text: G/^/M0Make the first row the last row, the second row the last row, and the last row the first row.


Original article, reproduced please indicate the source: http://www.cnblogs.com/DayByDay/p/3921799.html
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.