Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The difference between vi and vim

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Vim is a text editor developed from vi. The convenient programming functions such as code completion, compilation and error jump are particularly rich and are widely used by programmers. Juxtaposed with Emacs as the favorite editor for users of Unix-like systems.

The first version of Vim was released by Bram Moolenaar in 1991. Originally abbreviated as Vi IMitation, with the increasing number of features, the official name was changed to Vi IMproved. Now it is released freely in the open source mode.

First, let's look at the text.

Content edited by the first vi

Second, let's look at the effect of vim.

Vim has 6 basic modes and 5 derived modes.

1. Basic mode

(1) normal mode

In normal mode, users can execute general editor commands, such as moving the cursor, deleting text, and so on. This is also the default mode after Vim starts. This is the opposite of what many new users expect (the default mode of most editors is insert mode).

A large part of Vim's powerful editing power comes from its normal mode commands. Normal mode commands often require the end of an operator. For example, the normal mode command "dd" deletes the current line, but the first "d" can be followed by another move command to replace the second "d". For example, you can delete the current line and the next line with the "j" key that moves to the next line. You can also specify the number of times the command is repeated, "2dd" (repeat "dd" twice), and "dj" has the same effect. Users have learned a variety of text-to-text move / jump commands and other normal mode editing commands, and if they are able to combine them flexibly, they can edit text more efficiently than those without mode.

In normal mode, there are many ways to enter insert mode. The more common way is to press the "a" (append/ append) key or the "I" (insert/ insert) key.

(2) insert mode

In this mode, most keys insert text into the text buffer. Most new users want to maintain this mode throughout the text editor editing process.

In insert mode, you can press ESC to return to normal mode.

(3) Visual mode

This model is similar to the normal model. But the move command expands the highlighted text area. The highlighted area can be a character, a line, or a piece of text. When a non-moving command is executed, the command is executed on this highlighted area. Vim's "text object" can be used in this mode as well as the move command.

(4) selection mode

This pattern is similar to the behavior of a schemaless editor (in the way of Windows standard text controls). In this mode, you can use the mouse or cursor keys to highlight the text, but if you enter any character, Vim replaces the selected highlighted text block with that character and automatically enters insert mode.

(5) Command line mode

In command line mode, you can enter text that will be interpreted and executed. For example, execute commands (":" keys), search ("/" and "?" Key) or filter command ("!" Key). After the command is executed, Vim returns to the mode before the command line mode, usually normal mode.

(6) Ex mode

This is similar to command-line mode, where you can execute more than one command at a time before leaving Ex mode with the ": visual" command.

two。 Derivation mode

(1) operator wait mode

This derived mode refers to the normal mode in which the Vim waits for an "action" to complete the command after executing an action command. Vim also supports the use of "text object" as an action in operator wait mode, including "aw" a word (a word), "as" a sentence (a sentence), "ap" a paragraph (a paragraph), and so on.

For example, in normal mode, "d2as" deletes the current and next sentence. In visual mode, "apU" capitalizes all letters in the current paragraph.

(2) insert normal mode

This mode is entered when the ctrl-o key is pressed in insert mode. At this point, you temporarily enter normal mode. After executing a command, Vim returns to insert mode.

(3) insert visual mode

This mode starts when you press the ctrl-o key in insert mode and start a visual selection. When the visual area selection is canceled, Vim returns to insert mode.

(4) insert selection mode

This mode is usually entered by mouse dragging or shift arrow keys in insert mode. When the selection area is canceled, Vim returns to insert mode.

(5) replacement mode

This is a special insert mode in which you can do the same thing as the insert mode, but each input character will overwrite the characters that already exist in the text buffer. Press "R" key to enter in normal mode.

Other

Evim

Evim is a special GUI schema designed to behave as much as possible like a "schemaless" editor. The editor automatically enters and stays in insert mode, and the user can only manipulate the text through menu, mouse, and keyboard control keys. You can enter "evim" or "vim-y" at the command line. Under Windows, you can usually click the Evim icon on the desktop.

Function

Summary

Vim provides a large number of documents in text form. And Vim provides a variety of functions in order to quickly find a solution to the problem. According to Vim's own help file syntax, keywords are represented in a variety of eye-catching colors. You can use keyboard shortcuts to browse the help file as if you were in a browser. In the GUI version of Vim, you can also use the mouse to move through the help file. There are more functions that make it easier for users to find a solution to the problem, the most important of which is the': helpgrep' command. Using this command, users can search all the help files for what they want to see, use': cwindows' to express the search results in another window, and automatically jump in the help files according to the search results. Using the help function of Vim, you can continue to search in the search results.

Functions related to program development

Vim is an editor developed by programmers for convenience in writing programs. Vim has a variety of features that make writing code easy and enjoyable. Like the integrated development environment, Vim has the ability to be configured to compile directly after editing the code source file. In the case of compilation errors, errors can be displayed in another window. According to the error message, jump directly to the error location of the source file you are editing. Code highlighting, text folding, and context completion are all features that are particularly helpful to programmers (reference': help quickfix')

File comparison

Text files can be compared line by line. Vim can display two versions of the file side by side, with differences in a variety of colors. Lines that have been changed, added, or deleted are highlighted in color, and those that have not been changed are automatically folded.

For the two buffers that have been opened in vim, use: diffthis will then compare the contents of the two buffers, and the compared buffer can be a buffer in memory that has not been saved.

When comparing the differences between the two files, you can use the diffget and: diffput commands to synchronize each difference in both directions, or you can make other edits to the content while comparing, and then use: diffupdate to re-compare the latest content.

When browsing the differences between the two files, you can jump directly to the difference between the previous and the next with the commands in [c] c Normal mode.

Options such as diffopt can give you finer control over which differences are considered to be real differences, such as setting the number of white space characters to be ignored when comparing.

You can use the vimdiff command to use this function under Unix.

Script language

Vim has its own scripting language, and macros written in scripting languages can automate complex operations. The Vim script can be executed either by starting Vim with the-s option, or by switching directly to the directory where the macro is located and using the': source' command. The configuration file of Vim can be used as an example of Vim script. The name of the configuration file under Unix and Linux is .vimrc, and the configuration file under Windows is generally called _ vimrc. This file is automatically executed when Vim is started. The Vim scripting language can use all commands in Vim command-line mode, and all commands in normal mode can be used with the': normal' command. Vim scripting language has two data types: number and string. Use numbers to represent Boolean types, 0 for false, and all other numbers for true. The latest Vim 7 also provides advanced data structures such as lists and associative arrays. The Vim scripting language also has a variety of comparison and arithmetic operators. The control structure realizes if branch and for/while loop. You can also define functions yourself, and you can use more than 100 predefined functions. The script file can be debugged in debug mode.

shortcomings

They are all multi-mode editors, except that vim is an upgraded version of vi, which is not only compatible with all the instructions of vi, but also has some new features in it.

These advantages of vim are mainly reflected in the following aspects:

1. Multi-level undo

We know that in vi, pressing u can only undo the last command, while in vim you can undo it indefinitely.

2. Ease of use

Vi can only run in unix, while vim can not only run on unix,windows, mac and other multi-operating platforms.

3. Highlight the grammar

Vim can highlight your code in different colors.

4. Visual operation

That is to say, vim can run not only on terminals, but also on x window, mac os, and windows.

5. Full compatibility with vi

In some cases, you can use vim as a vi.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report