Learn vi and vim editors (3): simple text editing (2), vivim

Source: Internet
Author: User

Learn vi and vim editors (3): simple text editing (2), vivim

In the previous article, I will continue to explain some simple text editing commands in the vi editor. This article mainly involves commands such as text deletion, copying, and moving.

Delete text:

As mentioned in the previous article, the DELETE command ("d") also has the form of "(command) (TextObject, command represents commands such as Delete ("d") and replace ("c"), while TextObject refers to the cursor movement command, which represents the range of text objects affected by command. As long as you remember this, you do not need to remember the combination of the next DELETE command:

Dw: Delete the cursor to the end of the word (w is to move a word backward in the cursor movement command). Note that this command will delete the blank space after the word;

De: it is the same as the dw command, but will not delete the blank space after the word;

DE: Delete to the end of a word including punctuation marks;

D $: Delete the cursor to the end of the row, which is the same as the D command;

D0: Delete the cursor from the beginning of the row;

Dd: The entire row is directly deleted no matter where the cursor is in the row;

There are more than one combination of the d command and the cursor movement command, so we will not give an example here. As long as we understand the form of the combination, we do not need to remember it. Here are two additional cursor movement commands: "e" and "E", both of which move the cursor to the end of the word, but the "e" command moves to the end of the word, the "E" command is moved to the punctuation mark of the word.

If you need to delete characters, there are simpler commands, of course, these commands can also add numerical parameters:

X: Delete the character of the cursor;

X: delete a character before the cursor;

An error occurred when deleting the file: if the text is deleted by mistake, how can this problem be solved? You can use the u command to undo the previous command. However, since u only revokes the most recent command, u command recovery can only be used when other editing commands are not yet issued. I personally think there is a problem in the book, because when I delete 10 rows in a row, and then press 10 u consecutively, the original State can still be restored, as shown in, 10 rows to be deleted:

When you press ten "dd" commands in a row and then press ten "u" commands in a row to restore the original state, so I think there is a problem in the book. record it for now.

Move text:

In the vi editor, you can move a text block by deleting it before placing it. Each time you need to move a text block, you can delete it first, in this way, the content of the text block will be stored in a special buffer, move the cursor to the correct position, and place the deleted text in the new position using the placement command (p, to move the text.

P: place the buffer text after the cursor. If one or more lines of text are moved, it is a new row placed after the cursor. If not, move the text to the same row after the cursor;

P: similar to the p command, it only places the text in the buffer area before the cursor;

Note that the "p" Command places the deleted text to a new location, so you must restore the deleted text before performing the next delete operation, otherwise, if you make an edit action (delete, drag, and so on) that affects the buffer zone, the currently deleted text will disappear.

Similarly, you can use the "xp" command to reconcile two letters.

Copy text:

Copying text is implemented by two Commands: "y" (drag) and "p" (place. The "y" command is also used as a (command) (TextObject), so you can combine the drag command and the cursor movement command to specify the text range to be dragged. The combination of the drag command and the cursor movement command is no longer listed here, but in special cases, the "Y" command is equivalent to the "yy" command, all indicates dragging a whole line (in the delete or replace command, D is equivalent to d $, and C is equivalent to c $ ).

The drag command and the DELETE command share a buffer, so each new delete or drag command overwrites the content in the buffer.

Repeat:

The duplicate command is ".", and the previous command is directly repeated.

Undo command:

As mentioned above, when an error occurs, you can use the "u" command to cancel the previous operation. The "U" command can cancel all the editing actions on the same line, but the cursor must be on this line. Once the cursor leaves this line, you cannot use the U command to restore the original line.

More ways to insert text:

In the previous article, the commands "I" and "a" are used to insert text. In fact, there are multiple commands for inserting text:

A: Add text at the end of A line;

I: Add text at the beginning of a line;

O: Add a new row to the next row where the cursor is located;

O: Add a new row to the last row where the cursor is located;

Besides the o and O commands, all the insert commands mentioned earlier can accept numerical parameters. For example, "50i * ESC" can directly Insert 50 "*" characters, "10a *-ESC" can directly add 10 "*-" character pairs, "2r *" you can directly replace the two characters after the current cursor with two "*". As shown in: the Key order is "50, I, *, ESC", and 50 "*" appear. It doesn't feel like it is coming out right away. It takes nearly one second:

Use the J command to merge two rows. if you add a numerical parameter before the J command, you can specify the number of rows to be merged.


Summary of the vi editor commands in this chapter:

D, D, dd, e, E, p, y, Y, yy,., u, U, A, I, o, O, J.


How to learn the Chinese version of VI and VIM editors

A good book. You can search for pdf in English. Although it is English, the words in it are simple, and the author wrote very well. I really recommend it! Don't be afraid of English... try it.

Efficient text editor vim

New year, New Year, Spring Festival couplets, fireworks, really lively! Send a text message to ask, and raise your post to a fortune! Add more points.

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.