Vim editor notes

Source: Internet
Author: User

Emacs said, I only need an editor, but you gave me an operating system. It is a hacker's editor. If I fail to make Emacs into an operating system, I need a pure editor.

The following are common commands of the vim Editor:

Insert mode: it refers to text insertion, that is, the most familiar visible editing status. Press I, A, O, Shift + O to enter the insert mode. This is the easiest way to accept, so we put it first. If you are unfamiliar with commands, you can use the insert mode to adapt, and then learn various commands to gradually enhance the editing capability.

"Normal" Mode: Press ESC to enter the "normal" mode. In fact, it is not "normal" at all. More accurately, it should be "command control mode ", in this mode, you enter the command and then the editor responds appropriately, just like pressing the combined control key. This mode is used by default when Vim is started. The following commands can only take effect in this mode. When you type a command, VIM displays the command you typed in the bottom line of the editor.

Num-cmd-object: Vim command mode, which indicates that the command cmd has been executed for the object for num times. For example, 3j indicates moving down three rows. Very powerful!

 

J: Move to the next line; K: Move to the last line; H: the first character; L: The last character.

X: delete a single letter at the cursor position; DW: delete a single word at the cursor position; d $ Delete All characters from the cursor position to the end of the row; DD: Delete the entire row where the cursor is located.

P inserts the last deleted content. When used with DD, it can usually be used for cutting/pasting; U is used to cancel the previous operation;

R replacement mode. After pressing R, the entered characters will replace a single letter at the cursor's position. Shift + R: after pressing SHIFT + R, the entered characters will directly overwrite the character at the cursor's position, continuous replacement.

CW: delete a word and enter the insert mode.

CTRL + G display the row information of the cursor at the bottom of the editor; num + Shift + G jump to the specified row num. [Positioning]

Search string: // the string to be searched. To continue searching, press N. To reverse searching, press SHIFT + N [Search/replace]

Replace string: S/oldstr/newstr with the first match;: S/oldstr/newstr/replace all matches;

: #1, #2 S/old/new/g replace all matching rows #1 and #2;: % s replace in text

In brackets (), [], {}, you can jump to the matching brackets by % and return to the original brackets twice;


: Q exits when the file is edited without being saved. A warning message is displayed. W writes the content to the file, which is equivalent to saving the file. : WQ saves the file content and exits. [File operations]

: W filename writes the file content to the file filename, which is equivalent to saving as;: #1, #2 W filename: Write the content between the row #1 and #2 of the file being edited into the file filename;

: R filename Insert the filename content at the cursor;: Open filename open the specified file filename

 

:! External command name: Call an external command, for example :! Ls;

O: Insert a row under the row where the cursor is located and enter the insert mode. Shift + O: Insert a row above the row where the cursor is located and enter the insert mode.

A: Enter insert mode at the next position where the cursor is located; A: Enter insert mode at the end of the row where the cursor is located.

: Set IC search/replace ignore case sensitivity;: Set HLS is to highlight the search result;: Set XXX to set the xxx option.

Fast Moving:

Num + [jklh]: for example, 10j moves 10 rows down; 0: moves to the beginning of the row; $: moves to the end of the row;

Num + F + character: move the cursor to the specified num character. For example, to move the cursor to the beginning of the row, you only need to type 4 FM to move the cursor to the last m of the row.

Num + F + character: move forward to the specified num character. For example, to move the cursor to m at the end of a row, you only need to type 4 FM.

W: Move to the beginning of the next word; B to the beginning of the last word; e to the end of the next word; GE to the end of the last word.

Code block indent:

ESC [go to normal mode]-> SHIFT + V [go to visual mode]-> j, k move cursor select code block range-> right indent, <left indent

Visual mode: one of the purposes is to select a large number of text blocks, which can be used in the copy/paste function.

Text clipboard/paste: ESC ---> SHIFT + V ---> J, K move the cursor to select a text block ---> D (cut function is completed) --> move the cursor to the position to be inserted (Other delete operations are not allowed) ---> P

Cut/paste text outside: ESC ---> SHIFT + V ---> J, K move cursor select text block ---> w tmp (Write File TMP) ---> go to the location of the file to be inserted --->: R TMP

Vim settings: modify the configuration file Vim/_ vimrc under the vim root directory

# Coding

Set number
Set nobackup
Set autoindent
Set smartindent
Set tabstop = 4
Set shiftwidth = 4
Set showmatch
Set ruler

# Solve Chinese garbled characters

Set encoding = UTF-8
Set incsearchg = UTF-8

Set termencoding = UTF-8

Set fileencoding = Chinese

Set fileencodings = ucs-bom, UTF-8, Chinese

Set langmenu = zh_CN.utf-8

Source $ vimruntime/delmenu. Vim

Source $ vimruntime/menu. Vim

Language messages zh_cn.utf-8

Language messages zh_cn.utf-8

Summary:

The power of the vim editor lies in its rich commands, which can control the editor to make various responses. Of course, you must be familiar with commands and be able to use them flexibly. In fact, it is not as difficult as the legend. If the default start mode is insert mode, it may be easier to accept. Continue learning ......

 

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.