Use the Vi/Vim Editor: Basics

Source: Internet
Author: User
Tags linux text editor

Use the Vi/Vim Editor: Basics

The VI editor is a command line-based, powerful text editor. It was first developed for Unix systems and subsequently transplanted to many Unix and Linux distributions.

On Linux, there is another advanced version of VI Editor-VIM (also known as VI IMproved ). VIM only adds more features to the strong functions of VI. These features include:

  • Supports more Linux releases,
  • Supports code block folding and syntax highlighting in multiple programming languages, including python, c ++, and perl,
  • Supports editing files through multiple network protocols, including http and ssh,
  • Supports editing and compressing files in an archive,
  • Multiple files can be edited simultaneously on the split screen.

Next we will discuss the VI/VIM commands and options. For the purpose of teaching, we use VI for example, but all commands can be used in VIM. First, we will introduce the two modes of the VI editor.

 

Command mode

In command mode, we can execute tasks such as saving files, running commands in VI, copying, cutting, and pasting, and searching and replacing. When we are in insert mode, we can pressEscape(Esc) Key return command mode

 

Insert mode

In insert mode, you can type the file content. In command mode, pressiEnter the insert mode.

 

Create a file

You can run the following command to create a file ):

  1. $ vi filename

Once the file is created or opened, we first enter the command mode. We need to enter the input mode to enter the content in the file. We have learned about these two models through the previous article.

 

Exit Vi

To exit from the insert mode, pressEscEnter the command mode. Next, we can use two commands to exit Vi based on different needs.

  1. Do not save and exit-input in command mode:q!
  2. Save and exit-input in command mode:wq

 

Move cursor

Next we will discuss the commands and options for moving the cursor in command mode:

  1. kMove the cursor up a row
  2. jMove the cursor down one line
  3. hMove the cursor to the left of a letter
  4. lMove the cursor to the right of a letter

    Note: You can use4kOr5lThe two commands move up four lines or five letters to the right.

  5. 0Move the cursor to the beginning of the row
  6. $Move the cursor to the end of the row
  7. nGMove the cursor to line n
  8. GMove the cursor to the last line of the file
  9. {Move the cursor to the previous section
  10. }Move the cursor to the next segment

There are also some commands that can be used to control the movement of the cursor, but the commands listed above should be able to cope with daily work needs.

 

Edit text

This section lists some commands used in the command mode. You can enter the insert mode to edit the current file.

  1. iInsert content before the current cursor position
  2. IInsert content at the beginning of the row where the cursor is located
  3. aInsert content after the current cursor position
  4. AInsert content at the end of the row where the cursor is located
  5. oAdd a row after the row where the current cursor is located
  6. OAdd a row before the row where the current cursor is located

 

Delete text

The following commands can only be used in command mode.EscEnter command mode. If you are in insert mode:

  1. ddDelete the content of the entire line where the cursor is located.ddAdd a number before, for example2ddYou can delete two rows starting with the row where the cursor is located.
  2. d$Delete from cursor position till end of line
  3. d^Delete from the cursor position until the beginning of the line
  4. dwDelete all content starting from the cursor position until the next word

 

Copy and paste
  1. yyCopy the current row.yyMultiple rows can be copied by adding numbers before
  2. pPaste the copied row after the cursor
  3. PPaste the copy row before the cursor

These are some basic commands that can be used in the VI/VIM editor. More advanced commands will be taught in future tutorials. If you have any questions or suggestions, please leave a message in the comment area below.

Vim Basics

Basic Vim tutorials

Make Vim an excellent C ++ IDE

Upgrade Ubuntu 14.04 to Vim7.4 to 8.0

Install the youcompleteme auto-completion plug-in Vim

Linux Vim Editor

Vim Text Editor

Install and configure the advanced version of Vim

Vim editor usage tutorial

Ubuntu 16.04 Vim YouCompleteMe Automatic Installation configuration and use

Linux text editor Vim basic tutorial

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.