[Tool usage] Vim getting started shortcut

Source: Internet
Author: User


Vim getting started shortcut

Luo chaohui (Http://blog.csdn.net/kesalin)

Reprinted please indicate the source


 

Vim and EMAC are both powerful tools. Some time ago, I decided to familiarize myself with a set of cross-platform editors, so that I could have the same editing experience in windows, Mac, and ubuntu.

So I tried vim and used it for a while, which is indeed more efficient than UE and so on. On the win platform, gvim and macvim are available on Mac.

 

The learning curve of VIM is indeed steep, and it is not so easy to get used to at the beginning. It is essential to view help documents. The link to the online Chinese document is as follows:

Vim online Chinese documentation: http://vimcdoc.sourceforge.net/doc/help.html

 

This document is very big and comprehensive for easy reference. If you want to get started with vim, It is not suitable. Below I have sorted out some common shortcut keys to help you get started.

 

 

========================================================== ==============================

Mode operation

========================================================== ==============================

 

Vim has five basic modes. The default mode is normal mode and cannot be edited in normal mode. You need to enter the insert mode.

(Use NotePad to open a TXT file in window. The insert mode is used by default, so you can directly edit the file. Vim is not like this !!)

========================================================== ==============================

Normal Mode)

Insert mode)

Command mode)

Visual Mode)

Replace Mode)

 

 

In other modes, return to normal mode:

========================================================== ==============================

ESC

CTRL + c

CTRL + [

 

Enter insert mode

 

========================================================== ==============================

Iinsert Insert before the cursor

Iinsert before the first non-blank character of the current row

Aappend Insert after the cursor

Aappend: Move the input point to the end of the row in the current row to input text.

O start a new row under the current row and enter the insert mode.

O start a new row above the current row and enter the insert mode.

Ssubstitute is used to delete characters under the current cursor and then enters the insert mode.

CW change word is rarely used, similar to S, except that the unit of deletion is word.

First, delete a word starting with the cursor (including the cursor) and enter the insert mode,

 

 

Enter the command mode:

========================================================== ==============================

:,/

 

: You can use the arrow keys to call up historical commands. Even after entering: S,

Filters historical commands and calls up only historical commands starting with S.

 

: HELP command to view help documentation

: View help in Command Line Mode

 

 

Enter the visual mode: This mode facilitates Text Selection

========================================================== ==============================

V, V, CTRL + V

 

Vvisual, visible, moving in characters

V visible, moving in behavior units

CTRL + V visible, move in Block

 

Visual Block Mode Application: Add multi-row // comment

 

First, move the cursor to the first line of the code block to enter the visual block mode,

Move the cursor to the first line of the last line of the code block, and a column is highlighted.

Enter I. Note that it is not I. The information area displays the insert mode,

Enter the annotator "//" to comment out the first line, while the other lines remain unchanged.

Don't worry. Enter ESC and return to normal mode.

At this time, the comments are added to the front of other selected rows, and all of them are commented out.

 

 

Enter replacement Mode

========================================================== ==============================

R, R

 

Rreplace, which is only used to replace a single character with the cursor.

R continues to be replaced until it exits the r mode. In this mode, it can be restored according to backspace.

 

========================================================== ==============================

 

For more information about the mode, see the Vim Help documentation and use the following command:

 

: Help mode-Switching

 

 

========================================================== ==============================

File Operations

========================================================== ==============================

 

Split Window

========================================================== ==============================

: SP vim.txt split, horizontal split window

: VS vim.txt Vertical Split, vertical split of the window visible block mode to complete.

 

Window Switching

========================================================== ==============================

CTRL + W + [H, J, K, L]

 

CTRL in VIM "^" generally indicates pressing CTRL

Wwindow

H, J, K, and l are the top, bottom, left, and right directions.

 

Close Window

========================================================== ==============================

CTRL + W + [c] Close the current window

CTRL + W + [O] Close other windows

 

Save files

========================================================== ==============================

: Wwrite, save the current file

: Wawriteall: Save all files

 

Exit File

========================================================== ==============================

: Qquit. Close the current window or current tab.

: Wqwrite + quit, save and close

 

 

========================================================== ==============================

Navigation and navigation

========================================================== ==============================

 

There are two types of movement in VIM: navigation and navigation.

Navigation is a small range of movement, while navigation is a large range and the cursor position is not fixed after execution.

In the Vim Help document, such operations are called motion operations. You can view the help information:

 

: Help Motion

 

 

Navigation

========================================================== ==============================

H, J, K, L, W, E, B, F, F, T ,,,;

 

H, J, K, L move up, down, left, right, and left

WWord, moving forward in words, with the cursor on the first letter

Eend, moving forward in words, with the cursor on the last letter

Bback, in reverse movement of words, with the cursor on the first letter

F + keyforward, move to the next occurrence character (key) location of the row,

Then you can press; forward or backward move

The usage of F + key is the same as that of F, but it is reverse moving.

Ttill, the effect is similar to F, Except F will place the cursor on the target character,

T places the cursor on the first character of the target character.

 

 

Jump

========================================================== ==============================

^, 0, $, %, [[,], GG, G, L, H, M, M, ',: [number]

 

^ Move to the first non-blank character in the row

0 move to the beginning of the line (refer to command I)

$ Move to the end of a line (refer to command)

% Matching characters ([{}]) that are being searched or adjusted in this row,

] Key combination, T in the text to jump to the next '{' character at the beginning of the line

[[Similar to], but reverse

Gg jumps to the first line of the entire text

G jumps to the last line of the entire text

Hhigh, jump to the first line in the text range displayed on the current screen

Llow: Jump to the last line in the text range displayed on the current screen

Mmiddle: move the cursor to the center of the text range displayed on the screen

The M key combination is related to the vim register (see the help registers)

M-mark, input m, and then input the register serial number (a-Z, a-z ),

Put the current cursor position information in the register to maintain, which is equivalent to setting the bookmarks.

'Key combination, followed by the register serial number, jump to the bookmarks set by m

: [Number] indicates the usage in command mode. Jump to the specified line. number indicates the number of rows.

 

 

Flip

========================================================== ==============================

CTRL + F, CTRL + B, CTRL + D, CTRL + u

 

CTRL + fforward, equivalent to Pagedown

CTRL + bback, equivalent to Pageup

CTRL + ddown, half page forward

CTRL + uup, Reverse flip half page

 

 

========================================================== ==============================

Edit operation

========================================================== ==============================

 

Delete

========================================================== ==============================

X, D + [jump/Move]

 

X cut, the content is saved in register x

D + jump/move Delete, key combination, delete and save the content to register x

Dwdelete word, positive Delete word

D0 is reversed to the beginning of the row.

D $ forward to the end of the row

Dd deletes the entire row

D ^ Delete the first non-blank character in the row

 

Mobile

========================================================== ==============================

X, Y, YY, Y, P, P, "+ Y," + P

 

Mobile text is actually a combination of operations:

Select the text to be moved;

Cut or copy the text;

Paste the text.

 

X cut

Yyank, copy, and save the content in register x

Y, YY copy the row where the cursor is located

Ppaste: extract the text stored in register X and paste it after the cursor position.

P is the same as P, but it is pasted before the cursor position.

"+ Y copy the text to the system copy clipboard (note that it is not the vim register X)

"+ P is used to pull text from the system copy clipboard for pasting.

 

Cancel redo

========================================================== ==============================

U, CTRL + R

 

Uundo, undo

CTRL + rredo, redo

 

Search

========================================================== ==============================

/+ Key

 

/Followed by the string to be searched, and then enter N for loop search. Regular Expression matching is supported for searching strings.

 

 

 

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.