Learning VI and VIM Editor: The main improvement of VIM for VI

Source: Internet
Author: User
Tags diff line editor

Vim has made a lot of improvements to VI, and this chapter discusses the main features added to Vim: including built-in Help features, startup and initialization options, new move commands, extended regular expressions, extended undo, custom executables, and more.

Built-in Help features:

Vim's documentation of more than 100,000 lines, almost all of the instructions can be obtained through the VIM built-in Help tool, the simplest form of using it is to invoke the ": Help" command. Use the built-in Help function to understand VI's navigational tips and know how to move forward and backward between tabs. When the cursor is over a label, press CTRL +] to go to the label and press "Ctrl+t" or "Ctrl+o" to return from the label.

The ": Help" command can be followed by a helpful topic, and the subject string we enter may match a string in the Vim Help topic now. For example, when you enter "Help Split" and then press the TAB key, the assist command loops between the string related to "split", such as "split ()", ": Split", and so on, to see a Help topic and press ENTER directly.

Startup and initialization options:

Vim can use different mechanisms to set the environment at startup, and Vim can also use a series of initialization files to define and adjust the hard-to-count combination of behaviors. To learn about Vim's startup details, you can use the ": Help Startup" command.

Command-Line options:

Vim's command-line options provide flexibility and power. Some options can invoke additional functionality, and some can suppress the default behavior. After the command-line options, you can list one or more files to be edited, and the file name can even be "-" so that Vim knows the input comes from the standard input. The following is a list of some of the command line options that Vim has but VI does not have (Vim already contains all VI options):

-B: Edit in binary mode;

-C Command:command will be considered as 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: Starts in diff mode. Vim performs a diff function of 2-4 files and can set options to simplify viewing of file differences. In Unix, Vim uses the diff command of the system to perform the diff task, and on Windows you can download additional executable files;

-e: Start with improved ex mode;

-G: Start Gvim (GUI);

-M: The Write option is turned off and the buffer cannot be modified at this time;

-O: All files open in their respective windows. You can specify the number of Windows to open (specified as integers, immediately following the O option), and the files listed on the command line are opened in a specified number of Windows. If the number of Windows exceeds the number of files, Vim opens a blank window to meet the quantity requirement. If the number of Windows is less than the number of files, the remaining files are placed in the vim buffer;

-O: As with "-O", but open a vertically separated window;

-y: Run vim in easy mode, this option will make vim more intuitive for beginners, but experienced users will find it confusing;

-Z: Run in restricted mode, basically close all external interfaces and prevent access to system functions;

Behavior associated with the command name:

There are two versions of Vim: graphical and text, and UNIX users can get the desired behavior simply by using the following commands:

Vim: Start the text version of Vim;

Gvim: Start the graphical version of Vim. Typically, Gvim and Vim are two different executable programs. Gvim needs to open all GUI options when compiling vim. You can also use "vim-g" to start Gvim, in Unix, Gvim requires x Window System;

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

Rvim: Start vim in restrictive mode, all external access to the shell command is forbidden;

Rgvim: Same as Rvim, but for graphical version;

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

Rgview: Same as Rview, but for graphical version;

Evim,eview: Use Easy mode when editing or read-only viewing. This command does not have a corresponding graphical version, because Gvim has been considered as a simple operation mode;

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

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

System-to-User configuration files:

vim Find initialization files in a specific order, It executes the first set of instructions found (possibly in the form of an environment variable or file) and then begins editing. So the first item that Vim encounters in the following list is the only item that is executed in the list. The order is as follows:

1,VIMINIT: Environment variable, if the variable is not empty, VIM executes its contents as an ex command;

2, User's VIMRC file: VIMRC (VIM Resource) initialization file is a cross-platform file, in Unix system, VIM looks for the location of the file:" $HOME/.VIMRC "(note, in Unix, if". VIMRC "file does not exist and will try to find" _VIMRC "file);

The original book does not list 3 and 4, it may be considered that the two search locations in strict terms are actually used to initialize the VI editor, you can refer to the Learning VI and VIM editor (10): Advanced editing methods (1). But after all, setting up in both places also completes the initialization of the Vim editor, so I think it should be clear that these two locations are also listed. And in the original book 5 also did not specify is the current directory. The order of VIM initialization search can be learned by ": Help Startup", where the documentation is clearly written.

The VIMRC file is a good place to configure Vim editing features, and almost any option can be set in that file. Here are some considerations for VIMRC:

1, comments start with double quotation marks (") and can be anywhere on a line. All text enclosed in double quotes, including double quotes, is ignored;

2, can be used (or not) the colon represents the ex command;

3, if a large set of selection definition can be divided into different lines, this document will be easier to manage;

Environment variables:

There are a number of environment variables that affect the startup and editing behavior of vim, which lists the most obvious environment variables that are handled with default values when not configured:

shell: Specifies the shell that VIM uses to execute shell commands;

term: Set the internal term option within VIM. But this option is not really necessary, the editor will set its terminal in a way that it feels appropriate;

viminit: Specifies the command to be executed when Vim starts. Multiple commands are defined by a vertical line between commands,

exinit: Same as Viminit;

vimruntime: points to Vim-supported files, such as online documentation, plugin catalogs, etc. Usually vim can find these files by itself;

New Move Command:

VIM provides all the VI move commands while adding some commands:

Ctrl+end: Go to the last character of the last line of the file, and if you add a number, specify the line as a number and jump to the last character of the line;

Ctrl+home: Go to the first non-null character in the first line of the file. Or you can use the GG command. (Ctrl+end and Ctrl+home These two mobile commands do not work when I test, temporarily put this problem to write down first);

count%: Go to the line calculated based on the percentage of the file. The cursor is positioned around the first non-blank line near the line. It is also important to note that Vim is based on the number of rows in the file, not on the total number of characters;

: Go N or n Go: Go to the nth byte of the buffer, all characters including the last character of the line are counted;

The movement of the visual mode:

Vim allows the user to visually define the selected item and execute the Edit command on this visual selection. This feature is similar to the highlight effect that is caused by clicking and dragging the mouse in the graphical editor. Vim also allows us to use other commands as well as some special visual mode commands when defining visual selections.

Enter V in normal mode to enter the visual mode (enter V again to turn off the visual mode). After entering visual mode, any command that moves the cursor will also highlight the text in addition to moving the cursor to a new location. Also, in visual mode, VIM uses some unique commands that allow us to select text by selecting a text object near the cursor:

Countaw,countaw: Select the number of words specified by count. Spaces that separate words are not considered a word. The lowercase w treats the punctuation as a word, while the uppercase W only takes a space as the delimiter for the word;

COUNTIW,COUNTIW: Similar to the previous command, except that the space separating the words is also treated as a word;

As,is: Increase the selection of a sentence, or increase the selection of internal sentences (inner sentence, without spaces);

Ap,ip: Increase the selection of a paragraph, or increase the selection of internal paragraphs;

To learn more about text objects, you can use the Help command ": Text-objects."

An extended expression:

VIM provides a rich selection of regular expression matching tools, which can be consulted in the VI and Vim editor P173.

Custom executable file:

The current computer has provided ample processing power to the full-featured vim executable, and we can take all of the VIM extensions and make sure it performs well. In some cases, however, you need to get vim with a more concise function. At this point, it's much easier to recompile and install vim than to reconfigure with the new options.


This chapter VIM commands summary:

": Help", "Ctrl +]", "ctrl+t", "Ctrl+o", vim "-B", "-C", "-C", "-cmd", "-D", "-e", "-G", "-M", "-O", "-O", "-y", "-Z" option , 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".

Learning VI and VIM Editor: The main improvement of VIM for VI

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.