Vim Program Editor

Source: Internet
Author: User

The important task of a system administrator is to modify and set up configuration files for some important software, so at least you have to learn more than one command-line interface for this article editor.

At the end of this article, we will look at the knowledge of the text editor under the Linux system and how the program editor vim is used.

In the world of Linux, most of the configuration files are in ASCII plain text form, so the simple text editing software can be used to modify the settings.

I. Understanding the text editor under the Linux system

Linux has a large number of text editors under the command line interface, including Emacs,pico,nano,joe and Vim.

1. VI

The Importance of VI:

    1. All UNIX like systems will have a VI text editor built in, and other text editors will not necessarily exist;
    2. Many of the software's editing interface will actively call VI(for example, later talks to Crontab, Visudo, Edquota and other commands);
    3. Vim has the ability to edit the program, can be active in font color to identify the correctness of the grammar, convenient programming;
    4. The program is simple and the editing speed is quite fast.

The main point is the 2nd, because there are too many Linux commands on the default use VI as the interface for data editing, so we have to learn VI, otherwise we will not be able to operate a lot of commands.

2. Vim

We can view vim as a premium version of VI, and VIM can display some special information in the form of color or bottom line.

For example, when we use vim to edit a file in a C program language, or a shell script program that we follow up to, VIM automatically invokes the syntax of the program based on the file's extension or the initial information in the file to determine the contents of the file. Then display the program code and general information in color. In other words, this vim is a "program editor".

3. Vi. Summary of VI and VIM

VI is the old-fashioned word processor, but the function is very complete, but there is still a place to improve.

Vim can be said to be a very useful tool for program developers, even Vim's official website itself said that Vim is a "program development tool" rather than word processing software. Because Vim adds a lot of extra functionality (such as support for regular expression lookup architectures, multi-file editing, block copying, etc.), which is a great feature for us to make some configuration changes on Linux.

Ii. Use of VI

VI Three modes: General mode, edit mode, command line mode.

"General Mode"

Enter: Open a file with VI directly into the general mode, you can also switch from edit mode or command line mode.

Actions: Delete, copy, paste, etc., but cannot edit the contents of the file

"Edit Mode"

Enter: In general mode, press the letter I

Exit: Press the ESC key

Action: Edit File contents

"Command line Mode"

Enter: Press ":" "/" "? button, you can move the cursor to the

Action: Find data, save, replace character, leave VI, display line number, etc.

    • Special emphasis: In VI, the [TAB] key result is different from the result of the space character.

Third, the function of vim

I have to say that most of the VI is now replaced by Vim by default, that is, you use the VI command to open the file, and the default is to start the Vim editor.

Why use VIM? Because Vim has the function of color display, and also supports a lot of program syntax, when you use VIM to edit the program (whether it is C, or shell script), our vim will help you directly to the program debugging (Debug) function.

Here are a few additional useful features of VIM: Block selection, multi-file editing, multi-window functionality.

1. Block selection

In the process of simple VI operation, almost all operate in the unit of behavior. And if we want to fix a block range, we have to use the function of block selection.

2. Multi-file editing

Previously wanted to "move" the contents of a file to B file, usually open two Vim window to copy, but each vim is independent, so you have to circle through the mouse, copy and paste. But that's still a problem, because if we use the TAB key to arrange the alignment, the tab will be turned into a spacebar, so the content will be different.

Now this multi-file editor comes in handy.

Because we can use VIM to open two files. At this point we can use the command to copy and paste the contents of the file.

3. Multi-Window function

Displays two windows on one screen.

Specifically, there are two types of situations:

(1) Two Windows display the same file;

(2) Two Windows display different files.

In addition to the above features, we can also set our own VIM environment to make vim conform to our tastes.

Finally, I enclose a vim common command.

Iv. the use of vim precautions

1. Problems with Chinese encoding

There are a lot of Chinese coding, if the file with the vim of the terminal interface using different encoding, then the vim display of the file content will be a bunch of garbled.

2. Language encoding Conversion

Command Iconv can convert the language code, the command supports a lot of languages, including Simplified Chinese gb2312, Traditional Chinese Big5,utf8 encoding.

This means that we can use this command to do simple traditional conversion.

3. DOS and Linux segment line characters

DOS uses a break character of ^m$ (known as CR and LF two symbols), while Linux has only the LF ($) Break symbol.

While the following command in Linux starts execution, it is judged by [enter], and Linux [Enter] is the LF symbol, however, because the dos of the break symbol is CRLF, that is, more than a ^m symbol out, in such a case, if it is a shell The script's program file may cause the "program cannot execute" status because it will misjudge the command content being executed.

We just need to convert the format into Linux. Of course, there is no need to delete each row of CR, you can use simple commands to format the conversion.

Because DOS and Linux systems have different definitions for some of the characters below, we do not recommend that you edit the files in the Windows system before uploading them to the Linux system, which is prone to error problems.

Wu, restudying

    • The following configuration files for Linux are text files, so use Vim to edit the settings.

Vim Program Editor

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.