Vim Easy Tutorial

Source: Internet
Author: User
Tags see definition

1. Introduction:

Vim is a customizable text editor built into Linux that allows users to add functionality to their needs.

2. Use:

The operation of Vim is divided into three modes: General mode, edit mode, and command mode.

General mode:

When using VI to open a file, vi editor is in the general mode, in this mode, the user can only do simple operation: Use the arrow keys to move the cursor, delete characters, copy/paste content, etc., can not directly edit the content.

Edit mode:

To edit the text content, you need to press [I, I, O, O, A, a, R, R] any of these keys, and the VI editor will be in the editing state, and the user will be able to modify the text as needed. Here is a simple introduction to the key that opens the edit mode:

Command meaning
I Enter edit mode to insert from the previous position of the current cursor
I Enter edit mode to insert from the beginning of the line
O Enter edit mode to insert from the beginning of the following line of the paragraph where the cursor is located
O When you turn on edit mode, insert from the beginning of the previous line of the paragraph where the cursor is located
A Go to append mode, append from current position
A Enter append mode, append from end of line
R/r Replaces the current cursor position with the replacement mode
Command mode:

In general mode, the user simply enters [:,/,?] Any one of the three characters will enter the command mode, in the command mode, the user can use some commands to copy, paste, delete and other operations. If the user is in edit mode, you need to press the ESC key to exit to normal mode and then switch to command mode.

3. Shortcut keys

Vim Editor shortcut key is very convenient, when using the user can completely out of the mouse operation, below we introduce the commonly used shortcut keys.

General mode:
Command meaning
Esc Enter Command mode
~ Convert case
# Previous highlighted string
$ Jump to end of line
% Bracket Matching
^ Jump to beginning of line
X After a highlighted string
( The first sentence
) The first sentence
_ Beginning of previous line (note: underline instead of minus sign)
+ The beginning of the following line
W W: Next word
E E: Jump to the ending
R/r Replace character
Y Copy rows
u/u Undo Changes
i/i Enter edit mode
o/o Short Front/Jian line insertion
p/p Paste (before/after the cursor)
a/a Enter Append mode
S Delete characters and insert
S Delete a row and insert
D Delete the cursor in the row
{ Jump to the front of the paragraph
} Jump to end of paragraph
G Jump to end of file
H Jump to top row of screen
H Left ARROW key
J Merge two rows
J Down ARROW key
K Help (see definition of library functions)
K Up ARROW key
L Right ARROW key
X Delete character (equivalent to delete)
X BACKSPACE (equivalent to BACKSPACE)
C Delete the cursor to the end of the line
B/b Previous word
M Middle line of screen
N Find Previous
N Find the next place
< Reverse Indent with TAB key
> Indent with TAB key
Command mode:
command
: w
: w!
: Q close VI
: q! forcibly closes VI
: Wq
: w [filename]
: E [filename] open filename File
: H help
: R [FileName] filename The contents of the file are appended to the location of the cursor
: n1,n2 w [filename]
: Set nu display line number
: Set Nonu Cancel line number
Other IMPORTANT commands:
Command meaning
Ctrl+r Repeat
Ctrl+f/b Up/Down (in pages)
ctrl+e/y Roll up/Roll down (in behavioral units)
Ctrl+r Repeat Last Action
Zz Save exit
ZQ Do not save exit
Zt Move the cursor to the top of the screen
Zm Move the cursor to the middle of the screen
Zm Move the cursor to the bottom of the screen
Gg Move cursor to file start position
Gf Open the file name at the cursor (to view the contents of the header file)
Dd Delete the cursor in the row
Ndd Delete the n lines below the cursor
d1g Delete all contents of the line to the first line of the cursor
Dg Delete all contents of the line to the last row of the cursor
d$ Delete the content between the cursor and the end of the line
D0 Delete the content between the cursor and the beginning of the line
Yy Copy when moving forward
Nyy Copy the N-line content below the line where the cursor is located
y1g Copy all the contents of the line to the first line of the cursor
YG Copy all the contents of the line to the last row of the cursor
y$ Copy the contents of the cursor position to the end of the line
Y0 Copy the contents of the cursor position to the beginning of the line
NG Jump to Nth row
Nx Remove n consecutive characters backwards
/word Look for a string named word after the cursor
? word Look for a string named word before the cursor

By using the shortcut keys above, we can easily edit the document by completely leaving the mouse!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Vim Easy Tutorial

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.