Vi and vim Editor (15): main improvements to vi by vim, vivim

Source: Internet
Author: User
Tags line editor

Vi and vim Editor (15): main improvements to vi by vim, vivim

Vim has made a lot of improvements to vi. This chapter will discuss the main functions added to vim: includes built-in help functions, startup and initialization options, new mobile commands, extended regular expressions, extended revocation, and custom executable files.

Built-in help:

The vim instruction document contains more than 0.1 million lines. Almost all the instructions can be obtained through the built-in help tool of vim. The simplest way to use it is to call the ": help" command. To use the built-in help function, you need to understand vi's navigation skills and how to move forward and backward between labels. When the cursor is on a label, press "CTRL +]" to go to the label, press "CTRL + T" or "CTRL + O" to return from the label.

The ": help" command can be followed by a help topic. The input topic string may match a string in the current vim help topic. For example, after you enter "help split" and press the tab key, the help Command loops through the help topic strings related to "split", such as "split ()" and ()",": split ", etc. To view a help topic, press enter.

Startup and initialization options:

Vim can use different mechanisms to set the environment at startup. vim can also use a series of initialization files to define and adjust combinations of actions that are difficult to count. To learn about how vim starts, run the ": help startup" command.

Command line options:

Vim's command line options provide flexibility and power. Some options can call additional functions, and some options can suppress default behavior. After the command line option, you can list one or more files to be edited. The file name can even be "-" to let vim know that the input comes from the standard input. Next, list some command line options that vim has but vi does not have (vim already contains all vi options ):

-B: Edit in binary mode;

-C command: The command will be considered as an ex command execution;

-C: Run vim in compatible (vi) mode;

-Cmd command: command is executed before the vimrc file, which is also the long form of the-c option;

-D: Start in diff mode. Vim executes the diff function for 2-4 files and can set options to simplify viewing file differences. In UNIX, vim uses the diff command of the system to execute the diff task. In Windows, you can download the other executable files;

-E: Start in improved ex mode;

-G: Start gvim (GUI );

-M: Disable the write option. The buffer zone cannot be modified;

-O: All files open a window. You can specify the number of windows to be opened (specified by an integer followed by the o option). The files listed in the command line are opened in the specified number of Windows respectively. If the number of windows exceeds the number of files, vim opens a blank window to meet the quantity requirements. If the number of windows is smaller than the number of files, the remaining files are placed in the vim buffer;

-O: Same as "-o", but opens a vertically separated window;

-Y: Run vim in easy mode. For Beginners, this option will make vim more intuitive, but experienced users will be confused;

-Z: it runs in restricted mode. It basically closes all external interfaces and prevents access to system functions;

Behaviors related to command names:

Vim has two versions: The graphic version and the text version. UNIX users only need to use the following commands to obtain the required behavior:

Vim: Start the text version vim;

Gvim: Start vim for graphics. Generally, gvim and vim are two different executable programs. Gvim needs to enable all GUI options when compiling vim. You can also use "vim-g" to start gvim. in UNIX, gvim requires X Window System;

View and gview: Start vim or gvim in read-only mode. Same as "vim-R;

Rvim: Start vim in restrictive mode. All external access to shell commands is forbidden;

Rgvim: Same as rvim, but used for graphics;

Rview: Same as view, but started in restricted mode;

Rgview: Same as rview, but used for graphics;

Evim and eview: easy mode is used for editing or read-only viewing. This command does not have a graphic version, because gvim is considered a simple operation method;

Vimdiff, gvimdiff: Start in "diff" mode and compare the differences between input files;

Ex, gex: Use the ex line editor. Same as "vim-e.

System and user configuration files:

Vim looks for the initialization file in a specific order. It executes the first group of commands found (which may appear in the form of environment variables or files) and then edits the file. Therefore, the first project that Vim encounters in the following list is the unique project that is executed in the list. The order is as follows:

1. VIMINIT: environment variable. If the variable is not empty, Vim uses its content as the ex command for execution;

2. the user's vimrc file: vimrc (vim Resource) initialization file is a cross-platform file. In UNIX systems, the location of the file searched by vim is: "$ HOME /. vimrc "(note that in UNIX, if ". if the vimrc file does not exist, you will also try to find the "_ vimrc" file );

3. The content of the Environment Variable EXINIT: EXINIT will also be executed as the ex command;

4. Your exrc file: similar to the vimrc file. In UNIX systems, vim finds the file at "$ HOME/. exrc ";

5. exrc option: If the exrc option of vim is set, vim searches for three additional configuration files in the current directory. In UNIX, they are ". vimrc", "_ vimrc", ". exrc ";

The three and four items are not listed in the original book. Maybe the two search locations are strictly used to initialize the vi editor, refer to learning vi and vim Editor (10): advanced editing method (1). After all, setting these two locations can also initialize the vim editor, so I think we should explicitly list these two locations as well. In addition, the current directory is not specified in the original book 5. For more information about the sequence of vim initialization search, see ": help startup", where the help documentation is clearly written.

The vimrc file is a good place to configure the editing feature of vim, and almost any options can be set in this file. The following are precautions for vimrc:

1. The comments start with double quotation marks (") and can be located anywhere in a row. All text after double quotation marks, including double quotation marks, will be ignored;

2. You can use a colon (or not) to indicate the ex command;

3. If a group of selection definitions can be split into different rows, this file will be easier to manage;

Environment variable:

There are many environment variables that affect the startup and editing behaviors of vim. Here we list the most obvious environment variables that will be processed by default when not configured:

SHELL: Specifies the shell in which vim is used to execute shell commands;

TERM: set the internal term option in vim. However, this option is not really needed. The editor will set its terminal in the appropriate way;

MYVIMRC: overwrite vim's search for the initialization file. If the value of MYVIMRC is found at startup, vim assumes that the value is the name of the initialization file. If the file exists, it obtains the initialization settings and no longer searches for other files;

VIMINIT: Specifies the command to be executed when vim is started. Multiple commands can be defined using vertical lines to separate commands;

EXINIT: Same as VIMINIT;

VIM: The system directory path that contains the standard vim installation system information;

VIMRUNTIME: Point to files supported by vim, such as online instruction documents and plug-in directories. Usually vim can find these files by itself;

New mobile command:

Vim provides all the vi mobile commands and adds some commands:

Ctrl + end: Go to the last character of the last line of the file. If a number is added, specify the row as a number and jump to the last character of the row;

Ctrl + home: the first non-empty character in the first line of the file. Alternatively, you can use the gg command. (The Ctrl + end and Ctrl + home commands do not work during the test. Please note this question first );

Count %: Go to the row calculated based on the file percentage. Place the cursor on the first non-blank line near the row. In addition, vim uses the number of lines in the file as the calculation basis, rather than the total number of characters;

: Go n or n go: the nth byte to be transferred to the buffer. All characters, including the last line character, are counted;

Movement in visual mode:

Vim allows you to define the options visually and execute the edit command on the options. This function is similar to the highlighted effect caused by clicking and dragging the mouse in the graphic editor. Vim also allows us to use other commands and some special visual mode commands when defining visual options.

Enter v in normal mode to enter the visual mode (enter v again to disable the visual mode ). After entering the visual mode, in addition to moving the cursor to a new position, any command to move the cursor will highlight the text along the way. In the visual mode, vim uses some special commands to select text by selecting text objects near the cursor:

Countaw, countaW: select the number of words specified by count. Spaces that separate words are not considered a word. W in lower case regards punctuation as a word, while W in upper case only uses space as the word separator;

Countiw, countiW: similar to the preceding command, the space that separates words is also considered as a word;

As, is: Add or select an internal sentence (inner sentence, without spaces );

Ap, ip: Add and select a paragraph, or add and select an internal paragraph;

To learn more about text objects, run the help Command ": help text-objects ".

Extended in-process expression:

Vim provides a variety of Regular Expression matching tools. For details, refer to vi and vim editor P173.

Custom executable files:

The current computer has provided sufficient processing capabilities for the full-featured vim executable files. We can use all the vim extension functions and are sure that their performance is good. However, in some cases, you need to obtain vim with simple functions. At this point, it is much easier to re-compile and install vim than to reconfigure with the new option.


Summary of vim commands in this chapter:

": Help", "CTRL +]", "CTRL + T", "CTRL + O ", vim's "-B", "-c", "-C", "-cmd", "-d", "-E", "-g", and "-m ","-o ","-O ","-y ","-Z "options, vim, gvim, view, gview, rvim, rgvim, rgview, evim, eview, vimdiff, gvimdiff, ex, gex, "Ctrl + end", "Ctrl + home ", "gg", "count %", ": go n", "n go", "countaw ",

"CountaW", "countiw", "countiW", "as", "is", "ap", "ip ".

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.