Comparison of vim and VIM Installation

Source: Internet
Author: User
Tags return tag

When using the VI Editor, we found that the ESC key cannot be returned to the default mode. input the: HELP command, and we found that vim-tiny installed by default in Ubuntu is not complete in many functions. Install complete Vim for convenience. Note: In ubuntu, the VI and VIM commands actually use vim.

Vim has the following modes:

    • Normal Mode: the default editing mode. Unless otherwise specified, the commands mentioned are directly entered in normal mode; you can use the ESC key on the keyboard to return to normal mode in any other mode.
    • Command mode: used to execute long and complex commands. In normal mode, enter ":" (General Command), "/" (Forward search), or "?" (Reverse search) to enter this mode. In command mode, enter the Enter key.
    • Insert mode: used for text input. In normal mode, enter "I" (insert) or "A" (append) to enter the insert mode (there are other commands, for example, "C" can also enter the insert mode, but these commands have other functions ).
    • Visual mode: used to select text blocks. In normal mode, you can enter "v" (lower case) to select text blocks by character, and input "v" (upper case) to select text blocks by line, or enter "Ctrl-V" to select by Square.
    • Select mode: similar to the normal Windows Editor, select text blocks. After you select a text block in either visual or selection mode, you can use ctrl-g to switch to another mode. This mode is rarely used in Linux and will not be described in this article.

Installation Method:

Method 1: APT-Get install Vim

The system will install the vim and vim-runtime software packages. We recommend that you install vim-scripts, VIM-Doc, and ctags. It is best to install these recommended software packages because they can enable Vim to support syntax highlighting.

Method 2: Use Synaptic Package Manager (New Package Manager)

Install the vim, VIM-runtime, VIM-scripts, VIM-gnome, VIM-Doc, and exuberant-ctags packages.

After installation, enter the vim command on the terminal. The installation version is 7.2.245. Enter the Help Command, as shown below:

~ Vim-VI improved


~ Version 7.2.245

~ By Bram moolenaar et al.

~ Vim is open source and freely distributable


~ Become a registered Vim user!

~ Type: help register for information


~ Type: Q to exit

~ Type: help or for on-line help

~ Type: Help version7 for version info

Differences between VI and VIM

Vim has the following advantages:

1. Multi-Level undo we know that in VI, you can only undo the last command by u, but you can undo it without limit in vim.

2. ease of use VI can only run in UNIX, while Vim can run on not only UNIX, windows, Mac, and other multi-operating platforms.

3. Use different colors to highlight vim.Code.

4. Visualized operations mean that Vim can be run not only on the terminal, but also on X Windows, Mac OS, and windows.

5. fully compatible with VI. In some cases, you can use Vim as VI.

Comparison between vim and Emacs


Similarities between vim and Emacs:

The first is a full-featured editor.

Indent and re-orchestrate the format

Syntax highlighting

Unlimited "undo" and "redo"

Multiple Cutting and clipboard

Spelling check

Multi-language support

High scalability

Macro, Function

Custom key

Self-built. emacs and. vimrc (many people write these two files like tianshu, which may focus on memory)

OperationCompositionThis string, multiple rows, rectangular block

Almost any text file type can be identified

No row length and file size restrictions (except for operating systems)

Automatically identifies the line terminator of UNIX, Mac, and mswin

Binary File editing

They all provide great help, user manuals, and free e-books.

Both TTY and GUI versions are available.

Can run on many operating systems (* nix, Win32, Mac ...)

Both have fathers and elders: Emacs has xemacs and its derived epsilon and Jove; VIM has its elders VI, nvi, vile, and Elvis.

All are free software, which can be easily obtained


Vim and Emacs are different:

Vim is designed to writeProgramOf course, it can also operate a large number of text files; Emacs is mainly designed for text operations

Vim is small and fast to start. On the contrary, Emacs is large and slow to start.

Vim focuses on text editing, while Emacs is powerful: apart from what Vim often does, it also includes typographical, sending and receiving emails, IDE, playing MP3, calendar, system management, and web browsing, I even taught you how to make a beautiful Sichuan dish ...., powerful to BT. therefore, if Vim is a tool, emacs can be considered as a "life platform"

Vim learning curve is steep and short; Emacs learning curve is gentle and long

Vim is a pattern Editor, while Emacs is a pattern-free editor (many editors and word processors are currently in the pattern-free mode)

Advantages and disadvantages of "no mode"

Common and seemingly close

Easy to adapt to standard drop-down menu GUI programs

Its commands have complex syntaxes and combinations of multiple keys that are hard to be typed. Because the keys on the keyboard are limited, You can't add a pedal.

Even some keys are not on the standard keyboard.

Advantages and disadvantages of "mode available"

It is easy to confuse the current mode: Normal Mode, visual mode, select mode, insert mode, command-line mode, ex mode; ^ x mode, operator-pending mode, replace mode, insert normal mode, insert visual mode, and insert select mode are the modes that I can think of-so many, the header is big.

Frequent conversions between modes are annoying.

More buttons can be used for commands.

Almost all the time fingers are stuck at "normal position", so the efficiency is high.

Emacs's Gui makes it easier to operate large volumes of text work; gvim works better with XWindow -- it looks more comfortable: better-looking fonts, better syntax highlighting, nice tool bar and so on. the tty version of Emacs looks very similar to the GUI version, while the TTY version and gvim version of Vim are quite different.

Below are two mastersArticle(Emacs is a kind of belief! Introduction to the world's strongest Editor, dieken's editor for programmers-Vim

For the use of VIM in window, see:

Vim instructions

Most of the editors we use can directly enter characters in the editing area, and some shortcut keys can be used to complete some control functions, such as moving the cursor using the arrow keys and deleting text using the backspack or Delete keys, use pgup and pgdn to flip pages and use home and end to locate the first and last rows ......

Vim is a pattern-based editor. The same buttons have different function definitions in different modes. For example, H, J, K, and l enter the corresponding characters in editing mode, but in normal mode, they are equivalent to the direction keys.

The switch mode is cumbersome to use. But the advantages are also obvious: you only need to place your hands securely in the typing area, instead of using keys that need to be removed from your hands, such as direction keys, typographical keys, and keypad, this improves your efficiency and focus. In fact, when vi, the predecessor of VIM, was born, there were no direction keys, typographical keys, and keypad on the keyboard :)



VI [file name]

Vim [file name]

Use Vim to edit files

Vimtutor [language]

The Vim tutorial is equivalent to opening the tutorial file in read-only mode using the vim editor. No matter what you have done to this file, you will restore the original appearance after exiting. The difference between read-only mode and read-only mode is that it does not give you an eye-catching reminder. The current status is read-only mode. You can use it for some exercises.

You can specify the language of the tutorial file. If the local language (zh_cn) is garbled, you can try to use English

Vimtutor en

Vimdiff [file 1] [file 2] [other files]...

Configuration File


The global configuration file of VIM is "/etc/Vim/vimrc", and the user configuration file is "~ /. Comments line starting with "vimrc" and. The configuration items we provide can be added directly to the configuration file.

You can configure Vim first:

"Sets the file encoding.

Set fileencodings = UTF-8, ucs-bom, gb18030, GBK, gb2312, cp936

"Enable syntax highlighting

Syntax on

"Color Matching Style

Colorscheme Pablo

"The setting line spacing takes effect on the GUI.

Set linespace = 4

"Set GUI options

"Set guioptions = gmrltt M: menu T: Toolbar

Set guioptions = gmrlt

"Set the number of spaces for Tab key indent

Set tabstop = 4

"Sets the number of spaces in the editor as an indent.

Set shiftwidth = 4

"Set the folding Mode

"Set foldmethod = indent

"The following characters are considered part of a word (ASCII ):

"Set iskeyword + = 33-47,58-64,91-96,123-128

Mode Introduction


Common Vim modes include normal mode, insert mode, and command mode. In addition, we often use visual mode.

Enter normal mode when Vim is started. Alternatively, Press ESC to return to normal mode.

Run the "vimtutor en" command to go To the tutorial. Now it is in normal mode. Press the "J, K, L, H" key to change the cursor position.

Press the "I" key and "-- insert --" or "-- insert --" appears at the bottom of the editor. You enter the insert mode. Press "J, K, L, and H" to display the corresponding characters in the editing area. You can also move the cursor using the arrow keys.

You may think that moving the cursor with the direction key is not a problem, but after you get used to VIM, you will think that the direction key is too troublesome to tolerate! Now press ESC to return to normal mode. We can use J, K, H, and l to move the cursor.

In normal mode, press the ":" Key (that is, Shift +;) and a ":" is displayed at the bottom of the editor. You enter the command mode. Enter "new" after ":", and press Enter. The editor is split into the upper and lower columns.

For convenience, we add a ":" before the command to indicate the command entered in command mode.

: Vnew

A command can be simplified by some rules. The preceding command can also be written in this form.


Now, your editing area must be broken down. You can use the command ": Quit" to close the current column. simply use the shorthand.

: Q

This command exits the editor. If the editing area is divided into multiple columns, it exits the current column.

After executing a command (Press ENTER), The Editor automatically returns to normal mode. If you want to directly return to normal mode without executing the current command, you can press ESC.

Press the "v" key to enter the visual mode. You can use "J, K, L, H" to move the cursor and highlight the selected text.

In fact, the visual mode is equivalent to the normal mode after the highlighted text is selected.

The visible mode has a sub-mode. It selects the visible row mode based on the behavior unit and uses the "v" key to enter (that is, Shift + V ); and block-Based Visual block mode. Press Ctrl + V to enter.

Mode switch


Now, let's summarize the methods for switching between modes.

Other modes ==> Normal Mode


Normal Mode ==> insert mode

I insert before the cursor I insert at the beginning of the row

Insert a after the cursor at the end of the row

O create a new row under the current row

R replaces the current character R from the current character

Normal Mode ==> command mode


Normal Mode ==> visual mode

V visual mode

V visual Block Mode

Visual Block Mode



In normal mode, you can move the cursor as follows

J down

K up K

L right h L

H To left J

You can move the cursor more efficiently.

W. The first word w. The special symbol is considered as a part of the word.

B. The first word is the same as B.

E at the end of a word. e is the same as above.

0 rows first ^ line first text (line first after space)

$ End of line

H page top

Middle of M page

L bottom of the page

In other modes, you can use the arrow keys to move the cursor, but we do not recommend that you do that. You can bind the function keys in insert mode to the configuration file.






<Scope> <key position> <function>

Here, map! The bound keyboard ing acts on all modes; inoremap! The bound ing only applies to the insert mode.

Numeric Parameters


You can also use numeric parameters for repeated execution. For example

100 J keys are executed 100 times, and rows are down



You can mark the current cursor to quickly return

M <Tag Name> defines the tag. Mark the name as a character

'<Tag Name> return tag

MX defines the current cursor as marking x

'X return flag x



Next one page, next half page

One or more pages

Gg file first line

G file last line

<Row number> G is converted to the corresponding row by row number

<1 ~ 100> % convert to the corresponding number of rows by percentage

ZZ adjusts the row where the cursor is located to the center of the page

One row in the lower volume

Roll up a row

TIPS: Gg locates at the first line of the file, V enters the visible line mode, and g locates at the last line of the file to implement a function similar to "select all. Press g G v (SHIFT + V) g (SHIFT + G) in sequence)



X cut the current character

DD: Cut the current row

Y-copy select characters in visual mode

YY copy the current row

P paste after the cursor P paste before the cursor

U undo


Duplicate the last line of content

Duplicate the next line of content

Register operation


Vim can cut or copy different fields to different registers. You can extract and paste the content from different registers.

"<Register Name> press" "and another character key to define a register. For example:

"A" 1

Perform operations directly after defining the Register

"Ayy copies the current row to register

"AP pasted the content in register a after the cursor

TIPS: Generally, the register + ("+ (SHIFT + =) corresponds to the clipboard under X. You can use "+ P to paste the copied content in other programs into Vim. In vim, you can use" + Y to copy the content to the clipboard and then paste it into other programs.

When no register is specified, VIM uses "anonymous register" to store the content.

Search and replace


Press the "/" key and the "/" symbol will appear at the bottom of the editor. Then, enter a string to search.

/Search down? Search up

N search for the next

N search for the previous one

: S/<source string>/<target string> Replace the source string with the target string

: S/<source string>/<target string>/g to replace all matching strings in the current row

: <Line number 1>, <line number 2> S/<source string>/<target string>/g to replace in the specified line

: % S/<source string>/<target string>/g full-text replacement

Regular Expression


When searching and replacing, you can use regular expressions for matching.



You can record a series of operations as a macro and then execute it

Q <macro name> starts recording macros. Macro name is a character

In Q recording, press "Q" To End recording.

@ <Macro name> execute macro

Shortcut Keys in insert mode


<Register Name> enter the specified register content

<2 characters> two-character input

<Number> enter characters by numerical Encoding

<Key bit> name of the Input key bit

Key Binding and abbreviations


We have introduced you to key binding,


The angle brackets and their content are the conventions in the vim configuration file. The keys and functions are described respectively, indicating that the functions are compiled on the buttons. If only common characters are bound, for example:

Map! Xxx XXXXX

"XXXXX" is bound to "XXX. When you type "XXX", the editor will automatically replace it with "XXXXX ".

If you only want to bind the string to the abbreviation for easy input, we recommend that you use "iabbrev" to bind it. For example:

Iabbrev UBT Ubuntu

In insert mode, type "UBT". The editor will automatically replace it with "ubuntu ".

You can abbreviated the "iabbrev" command as "IAB", for example:

Iab ubt Ubuntu

You can enter the preceding commands in command mode to enable them temporarily. You can also write the configuration file and enable it permanently.

Word completion


Next match

Previous match

You can define the completion method in the configuration file.

"Automatic completion method: (separated by commas)

Set complete = K ,.

". Current File

"B has been installed with a buffer, but there are no files in the window

"D. Define and include files in the current file by # include

"I consists of # include files.

"K files defined by the dictionary Option

"The kfile name is {file }.

"T tag (TAGS) File

"U does not load the buffer.

"W files in other windows

"Set auto-completion dictionary:

Set dictionary = path

Command mode


The common mode and insert mode are described earlier. We found that the normal mode is mainly used to browse and modify the text content, while the insert mode is used to add content to the text.

The command mode is mostly used to operate text files (rather than the content of text files), such as saving files, or changing the editor status, for example, you can set a multi-column window, Tag, or exit the editor ......

W (rote) will change the write to file

: W

Q (uit) exits the editor

: Q

In some cases, the editor blocks command execution. For example, if you modify the file but do not save it, the editor will not execute this command when you exit using the ": Q" command, but will remind you to save the file.

At this time, you can append "!" at the end of the command. To force Command Execution

: <Command>!

For example, ": Q !", Even if you do not save the modified file, the editor will stop modifying the file and forcibly exit.

Take "!" Pilot a shell command, you can temporarily switch from Vim to shell and execute a shell

:! <Command>

For example:! Ls"

Multi-column window


You can use the following command to split the current window horizontally into two columns:

: New

Create a blank window

: Split

Split the current file into two columns

Similarly, you can use the following command to divide the current window horizontally into two columns:

: Vnew

: Vsplit

Press the key first, and then press the direction key "J, K, L, H". You can switch to another column. Use the ": Q" command in the current column to exit the current column, you can also use other commands to modify the current column.

If you want the current command to take effect in all columns, You can append "all" at the end of the command"

: <Command> All

For example:

: Qall

If you want this command to be executed forcibly, then "!" At the end of the command

: <Command> All!

For example:

: Qall! Force exit all columns



In Versions later than 7, VIM began to support the tab function.

: Tabnew create a tag

: Tabnext to the next tag

: Tabprevious to the previous tag

In most cases, you can use the mouse to click the label to switch.

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: 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.