Use of Vi text editor

Source: Internet
Author: User
VI and VIMvi are text editing tools on the command line interface. they were first developed by BillJoy in 1976 and were called ex. Vi supports the vast majority of operating systems (released on BSD at the earliest), and has very powerful functions, generally available in UNIX-like operating systems. In 1991, BrmMoolenaar was improved based on vi, and vim was released. VI, VIMVi is a text editing tool on the command line interface. it was first developed by BillJoy in 1976 and was named ex. Vi supports the vast majority of operating systems (released on BSD at the earliest), and has very powerful functions, generally available in UNIX-like operating systems. In 1991, BrmMoolenaar was improved based on vi. it released vim and added support for GUI.

Vim is not only the most common text editor (such as Notepad on windows), but also widely used in text editing, text processing, code development, and so on. The well-known text editor in Linu also has emacs, which is more powerful than vim.

Vim is an enhanced version of vi. vim is installed on most Linux systems. vim is more powerful than vi. Therefore, we recommend that you use vim instead of vi. The two are used in the same way.
Vimcommand can be used to start the vimeditor. generally, vim(viabc.txt) is used in the form of the vimworkflow target file. if the target file exists, vim opens the file. if the target file does not exist, vim creates and opens the file.
VIM has three modes:

Command mode (conventional mode): After vim is started, the command mode is enabled by default. in any mode, the esc key can be used to return to the command mode (several times more times ). In command mode, you can select, copy, paste, and undo different commands.

Insert mode: press the "I" key in command mode to enter the insert mode. in insert mode, you can enter and edit the text content, and use the esc key to return to the command mode.

Ex Mode: In command mode, press the ":" key to enter the ex Mode. the cursor moves to the bottom. here, you can save the changes or exit vim.

Command mode:After vim is started, it enters the command mode by default. in any mode, you can use the esc key to return to the command mode (you can press it several times more times ). Common commands in command mode are as follows:
I insert text before the cursor
O insert a new row under the current row
Dd deletes the entire row
Yy put the content of the current row into the buffer (copy the current row)
N + yy put the content of n rows into the buffer (copy n rows)
P put the text in the buffer into the cursor (paste)
U revokes the previous operation, which is equivalent to withdrawing
R replaces the current character
/Search for keywords

CTRL + r canceling the undo operation is equivalent to moving forward

In command mode, press the ":" key to enter the ex Mode. the cursor moves to the bottom. here, you can save the modification or exit vim. Common commands in ex Mode are as follows:
Common commands in ex Mode:: W: save the current modification
: Q exit
: Q! Force exit without saving changes
: X save and exit, equivalent to: wq
: Set number: displays the row number. you can directly enter set nu.
:! Execute system commands
: Sh switch to the command line, use ctrl + d to switch back to vim
: S/str1/str2/g replace str1 in the current row with str2
: % S/str1/str2/g replace str1 in all rows with str2, where % indicates all rows
:/Regexp: searches for a specified string. Regular expressions are supported. you can press n to jump to the next match, and then press N to jump to the previous match.

If you want to learn Linux well, you won't be able to understand it. it's mainly about multiple exercises. Just like learning five-stroke typing, you can get familiar with it without stopping typing. some basic operation commands have been written before, and you can continue to practice these commands.

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.