About the text editor for Linux

Source: Internet
Author: User

about the text editor

The text editor has many, gedit, KWrite, OpenOffice ..., the editor in text mode has VI, VIM (enhanced version of VI) and nano ... vi and VIM are the most common editors we use in our Linux. We need to introduce the simplest use of VI (VIM) so that Linux entry-level users will learn to work with it in the shortest time possible. Nano Tools and DOS operating system of the edit operation is similar, easy to use, we do not introduce, if you are interested, may wish to try;

VI Editor

Why learn to use VI VI or VIM is the most basic version of the Linux text editing tools, vi or VIM, although there is no graphical interface editor as the simple operation of the mouse, but the VI editor in the System management, server management, is never a graphical interface editor can be compared. When you are not installing the X-windows desktop environment or the desktop environment crashes, we still need the Editor VI in character mode, VI or the VIM editor for the most efficient tool in creating and editing simple documents;

How to use the VI editorHow to call VI

[[Email protected] ~]# VI filename ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

Three command modes for VI

Command mode, for entering commands, insert (insert) mode, for inserting text, Visual (visual) mode, for highlighting and selecting the body of the viewport;

saving and exiting files

Command mode is the default mode for VI or VIM, and if we are in other command modes, we need to switch through the ESC key. When we press the ESC key, then enter the: number, VI will be at the bottom of the screen waiting for us to enter the command;: w Save; : w filename Save as filename; : wq! save exit;

wq! filename Note: The filename is saved and then exited;
q! does not save the exit;

: x should be saved and exited, function and: wq! same

Cursor Movement

When we press ESC into command mode, we can use some of the following keys to move the cursor; J moves down one line; K moves up one line ;

H moves one character to the left, and one character to the right;

Ctrl+b Move up one screen; ctrl+f Move down one screen;

The UP arrow moves up, the downward arrow moves down, the left arrow moves to the left, the right arrow moves to the right, and when we edit a file, the J, K, L, and H keys are also preceded by a number in front of these action commands, such as 3j, that moves down 3 rows.

Insert mode (insertion of text)

I insert before the cursor; A is inserted after the cursor;

I Insert at the beginning of the line where the cursor is located; A is inserted at the end of the line where the cursor is located;

o Insert a row above the line where the cursor is located; o Insert a row below the line where the cursor is located;

s deletes a character after the cursor, then enters insert mode, s deletes the line where the cursor is located, and then enters insert mode;

deletion of text content

X a character , #x delete a few characters, #表示数字, such as 3x; DW Delete a word , #dw Delete a few words, #用数字表示, such as 3DW means delete three words, dd delete a row , #dd delete multiple rows, #代表数字, such as 3 DD means to delete the cursor line and the next two lines of the cursor, d$ delete the cursor to the end of the line ;

J clears the space between the line of the cursor and the previous line, connecting the line of the cursor to the previous row;

Redo and restore Delete operations

U undo the Modify or delete operation, press ESC to return to command mode, and then press U to undelete the previous deletion or modification, or press multiple times if you want to undo multiple previous modifications or deletions. This is not much different from the undo operation of Word;

Visual Mode

In the latest Linux distributions, VI provides visual mode because this function is vim. If you use the VI does not have this function, you can replace it with vim. Open the visual mode, press the ESC key, then press V to enter the visual mode, the visual mode gives us a very friendly selection of text range to highlight, display at the bottom of the screen has;--- visual--

Or

--visual--

Entering the visual mode, we can select the text range by using the cursor movement instruction in the preceding command line mode. What is the use of selecting a text range? We can delete the job for some part, press the D key to delete our selected content. When the content is selected, we press Y to copy, and D to delete; it's worth mentioning. The deletion also represents replication. We return to the command mode, then move the cursor to a location, and then press the Shift+p key to paste the content just removed. Let us mention here first, in the following article, we have to say in detail. Exit the visual mode, or use the ESC key;

actions for copying and pasting

In fact, the deletion also has the meaning of shearing, when we delete the text, you can move the cursor to a place, and then press shift+p key to paste the content in place, and then move the cursor to somewhere, and then press P or shift+p and can paste; p paste after the cursor; shift+p sticky before the cursor For example: We want to copy the third line of a document and post it to line fifth, what should we do? There are two ways to do this: first remove the third line, move the cursor to the third line, then use the DD action, then press the Shift+p key again. This puts the third line that you just deleted. Then we use the K key to move the cursor to line fifth, and then press the P key, so that the contents of the third line to the fifth row after the second method; Enter visual mode, press ESC, and then press the V key. Move the mouse pointer, select the contents of the third row, then press the Y key to copy, then move the pointer to line fifth, and finally press the P key, so the copy and paste operation is a combination of command mode, insert mode and visual mode; we have to learn to switch between the various modes, and to use the ESC key ; More important learn to move the cursor in command mode;

About line Numbers

Sometimes when we configure a program to run, there is an error in the configuration file X line. At this point we need to use the line number related operations;

Add line numbers for all content, press ESC, and then enter:

Set
number

The cursor is located in the lower right corner of the screen, similar to the following;

        57,8          27%

In this, 57 represents line 57th, and 8 represents the 8th character;

Find and Replace featuresFind

First, we have to enter the ESC key, enter the command mode; we enter the search mode;/search Note: Forward lookup, press the N key to move the cursor to the next qualifying place; Search Note: Reverse lookup, press Shift+n to move the cursor to the next qualifying example: for example, I want to find the swap word in a file, I should do the following, first press ESC, enter command mode, then enter; /swap or? Swap

Replace

Press ESC to enter command mode : s/search/replace/g Note: Replace the search word in the row where the current cursor is located, and highlight all search.

%s/search/replace Note: Replace all SEARCH in the document with replacement;

: #,# s/search/replace/g Note: The # number indicates the number of lines to how many lines, the search is replaced with replace; note: In this, G is the global lookup; We notice that the search is highlighted in places where there is no replacement, for example: For example, we have a document to be modified; we put the line where the cursor is, and replace all the words with the one, it should be:
: s/the/the/g
We replace all the entire document with the one, which should be:
:%s/the/the
We are simply replacing the 1th line to the 10th line, the one that should be;
: 1,10 s/the/the/g

About the text editor for Linux

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.