Essential for beginners of CentOS: Linux vi commands

Source: Internet
Author: User

In the current text editor era, the default Linux editor is still vi or vim. The Linux vi commands discussed in this article will help novice administrators better use vi.

This is inseparable from Linux vi or its latest version of vim. Why? Because vi is usually available regardless of the Linux server status. If the server encounters a problem and stops working, vi can fix it.

Some commands are based on vi and use vi as the default editor. The crontab command is used to schedule work. mongodo grants administrator privileges and edquota edits the file system quota, which are key parts of vi. The vi editor function promotes script writing, so the new Linux administrator Thinks vi is very useful.

If possible, select Linux vim. The new version of the text editor uses the availability function, such as statement highlighting. In some Linux versions, vim is enabled more automatically than vi. In other versions, the Administrator must specify vi or vim.

The vi commands discussed in this article apply to the Linux vi and vim editors.

Two Linux vi Modes

Linux vi has two modes, so it is a little difficult for new users. When you start vi to edit the document for the first time, you will enter the command mode vi ~ /Mydocument. However, before entering the command, you may want to enter some text. In this case, you need to enter the input mode.

The following command helps the Administrator switch between the vi and vim commands and the input mode:

Use a to enter the input mode after the current cursor position

Use I to enter the input mode at the current position of the cursor

Use o to open a new row

After entering text in input mode, use: wq! Write the changes to the disk and exit. Do not forget the commands starting with a colon. Make sure that letters are entered in the correct order and you cannot exit and then write them to the disk. Or use the alternative command: ZZ.

Sometimes the session in this article is not smooth. In that case, refer to the following practices:

Use u to cancel the previous modification (you can use it multiple times)

Use Ctrl-R to redo the undo Behavior

Use: q! As an emergency exit. It allows you to quickly exit from existing documents.

The Linux text file to be edited may become larger and larger. To place the cursor in the correct position, use:

Gg returns to the first line of the document

: Number to locate a specific number

/Text goes to the first place where "text" appears

G go to the end of the existing document

Some editing commands can also be used in vi command mode:

V enters the visualization mode. In visual mode, you can move the arrow key to select text.

D. delete an existing selection.

Y copy existing selection

P paste existing options

Dd deletes a row. Linux text editing usually needs to remove the entire line.

To search for and replace the given text, use: % s/oldtext/newtext/g

The "oldtext" section of the vi command should be the text you are looking. "Newtext" is the part you want to replace. This is a simple method for large-scale replacement in the document.

You can find many other available commands, but as a beginner in vi, it is a good idea to pay attention to the absolute minimum value. Using each Linux vi command to edit a text increases the risk of getting lost, so that you cannot find a suitable solution.


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.