Learn VI and VIM editor (3): Simple text editing (2)

Source: Internet
Author: User

Then the previous article continues to explain some simple text editing commands in the VI editor. This article is mainly the deletion of text, copying, moving and other commands.

Delete text:

As mentioned in the previous article, the Delete command ("D") also has the use of "(command)" (Textobject), where the command stands for commands such as delete ("D"), replace ("C"), and Textobject refers to the cursor Movement command, Represents the range of text objects affected by command. As long as you remember this, the next combination of DELETE commands doesn't have to be remembered:

de: Delete to the end of the word, including punctuation;

d$: Delete the cursor at the end of the line, Same as the D command effect ;

D0: Delete the cursor position to the beginning of the line;

DD: Deletes a whole row directly, regardless of where the current cursor is in the line;

The combination of the D command and the cursor Movement command is not only so much, there is no example here, as long as the use of this combination of understanding of the form, there is no need to remember. 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 itself, and the "E" command moves to the punctuation mark of the word.

If you need to delete characters, there are simpler commands, and of course these commands can also be added with numeric parameters:

X: Delete the character where the cursor is located;

X: Delete a character before the cursor;

problems when deleting files: If the text is deleted by mistake, how can it be remedied? you can use the U command to undo the previous command . However, since u only revokes the most recent command, the U command recovery can only be used when other editing commands have not been released. Personally feel that there is a problem in the book, because I deleted 10 lines in a row, and then continue to press 10 U, still can revert to the original appearance, as shown, is to delete the 10 lines:

In the continuous press 10 "DD" command, and then continuously press 10 "u" command to restore, still can restore to the most original appearance, so feel that there is a problem in the book, for the time being recorded first.

To move text:

The vi editor moves text through "Delete and then place text", and each time you need to move a block of text, the text block is deleted so that the contents of the text block are stored in a special buffer, and then the cursor is moved to the correct position. Use the Drop Command (p) to put the text you just deleted in a new position to move the text.

P: The text of the buffer is placed after the cursor, if a row and more than one line of text is moved, is placed after the cursor of a new row, if the move is not one line, the moved text is placed after the same line of the cursor;

P: Similar to the P command, except that the text in the buffer is placed before the cursor;

It should be noted that the " P" command is to put the text just deleted to the new location, so be sure to do the next delete action, the current deletion of this article to recover , otherwise if you do an impact buffer edit action (delete, drag, etc.), Then the currently deleted text disappears.

Similarly, a two-letter swap can be done with the "XP" command.

Copy text:

The copied text is implemented by two command "Y" (drag) and "P" (placement). The "y" command also has the use of (command) (textobject), so you can combine the drag command with the cursor Move command to specify the range of text that you want to drag. The combination of the drag command and the cursor Movement command is no longer listed here, but in a special case, the "Y" command is equivalent to the "yy" command, which means dragging a whole line (whereas in the Delete, replace command, D is equivalent to d$,c equivalent to C $).

The drag command and the delete command share a buffer, so each new delete or drag command overwrites the contents of the buffer.

Repeat:

Repeat command for "." and repeat the previous command directly.

Undo command:

as mentioned earlier, you can use the "u" command to undo the last action when an error occurs. "  u "command can undo all edits to the same line , but it requires the cursor to be in this line, and once the cursor leaves the line, you cannot use the U command to restore the original line.

More ways to insert text:

The previous article has said "I" and "a" two commands to insert text, in fact there are several commands to insert text:

A: Add text at the end of a line;

I: Add text at the beginning of a line;

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

O: Add a new line to the previous line where the cursor is located;

In addition to the O and O commands, the numeric parameters can be accepted in all insert commands that were previously spoken. For example, "50i*esc" can directly insert 50 "*" Characters, "10a*-esc" can directly add 10 "*" character pairs, "2r*" can directly replace the two characters after the current cursor with two "*". As shown: The key sequence is "50,i,*,esc", then there are 50 "*", the feeling is not immediately out, to wait nearly 1 seconds:

Merge two rows with the J command, and if you precede the J command with a numeric parameter, you can specify the number of rows that need to be merged.


This chapter VI editor commands summarize:

D,d,dd,e,e,p,y,y,yy,.,u,u,a,i,o,o,j.

Learn VI and VIM editor (3): Simple text editing (2)

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.