Go to VIM Quick Start

Source: Internet
Author: User
Vim Quick Start

20:19:13 | classification: Linux | report | font size subscription

Vim has three modes: normal (visual command) mode, command line mode, and edit mode. Start vim and Press ESC in any mode to enter normal mode. In normal mode, enter: Press enter to enter the command line mode. At this time, the bottom line of the vim window is: you can enter the command line command. Make sure that the command is in the corresponding mode before running any command.

1. Start and exit

1) VI filename (start Vim)

2) In command line mode: WQ => Save and exit, Q! => Force exit,: E! => Discard modifying file content, re-load the file,: x => exit, change and save the file, ZZ => same: X command (exit Vim)

 

2. Basic settings-in Command Line Mode

 

  • : Set nu display row number
  • : SYN on display syntax highlighted
  • : Set shiftwidth = 4 set Automatic indent 4 spaces, of course, you must set Automatic indent first.
  • : Set STS = 4: Set softtabstop to 4. After Entering the tab, the four cells are displayed.
  • : Set tabstop = 4 the actual tab is 4 spaces, instead of the default 8.
  • : Set expandtab after entering the tab, VIM fills the tab with appropriate spaces.
  • : Setsuffixes =. Bak ,~,. O,. H,. info,. SWP,. aux,. BBL,. BlG,. DVI,. LOF,. Log,. Lot,. ps,. TOC
  • When you open a file in Vim, it ignores the above files when you press the tab key to complete the file name.
  • : Set ENC = UTF-8 set text encoding

Set the configuration file:

: Scriptnames: list the directories where the configuration file. vimrc is located

: Location of the configuration file. vimrc used by the version user

 

 

3. Position the cursor (normal and visual)

$ End of the current row

0 indicates the beginning of the current row.

^ The first letter in the current row

Gg File Header

G file tail

''Back to the position before the cursor jump

H jump to the first line on the screen

M jumps to the middle line of the screen

L jump to the last line on the screen

W: move the cursor forward to the first letter of the word

B: opposite to W, move backward to the first letter of the word

E: move the cursor forward to the last letter of the word.

Ge: opposite to E, move backward to the last letter of the word

%: Move to the matching brackets (), {}, [], <>, etc.

CTRL + G to get the position of the current cursor in the file

Pagedown: Ctrl + F

Pageup: Ctrl + B

Move down the half screen: Ctrl + d

Move up half screen: Ctrl + u

Note:

. Cursor positioning (normal mode, visual mode) $0 at the end of the current row start of the current row ^ the first letter of the current row Gg File Header g file tail ''is returned to the position before the cursor jump H jump to the first line of the screen M jump to the screen to the last line on the screen W: move the cursor forward to the first letter of the word B: opposite to W, move backward to the first letter of the word E: move the cursor forward to the last letter of the word Ge: in contrast to E, move backward to the last letter % of the word: Move to the matching brackets ()...

Addition of cursor positioning techniques:

''Like ''' -- this command is quite useful. It moves the cursor to the previous tag, for example, using Gd, *, and other queries.

After finding a word, enter this command to return to the position where it was last stayed.

'. -- This command makes it very easy to move the cursor to the last modified line.

'. -- This command is quite powerful. It moves the cursor to the last modification point.

Note:

Line number + G jump to specified line

FX jumps to X of the row to the right (X can be any character)

FX jumps left to X (X can be any character)

TX and FX are the same. The difference is to jump to the character before X.

TX and FX are the same. The difference is that

 

4. Delete and copy (normal and visual)

Delete:

  • DD: delete a row
  • DW: to delete a word, move the cursor to the first letter of the word.
  • D $: Delete the letter from the current cursor to the end of the row
  • DAW: delete a word. The cursor is at any position of the word.
  • Dnw: delete n words
  • DNJ: delete n rows down
  • DNK: delete n rows up
  • J: Delete the line break, move the cursor to the new line, and press SHIFT + J to delete the line break at the end of the line. The next line is connected.

Copy:

  • YY: copy a row
  • YW: copy a word. move the cursor to the first letter of the word.
  • Yaw: copy a word. The cursor is at any position of the word.
  • Ynw: Copy n words
  • Ynj: Copy n rows down
  • Ynk: Copy n rows up

Modify:

  • CL: change the current character
  • CW: modifies the end of the current word.
  • Cc: modify the current row

Paste: P. paste the text operated by X, D, and Y.

In visual mode:

In visual mode, select the text to be edited and perform the operations D and Y.

Operations in the register:

You can specify a register before copying. The method is to enclose double quotation marks with a letter. For example, "A specifies register a," B specifies register B. Therefore, "Ayy puts the current row into register a, and then you can use" AP to paste the content in register. If you are not sure what is in the register, you can use: Reg to view it.

Vim provides a very useful special register "+, whose content is the content of the system clipboard. You can paste it with "+ P in vim.

 

5. Multi-File Operations

 

  1. : Ls (: buffers): displays the buffer list
    : Bn to the next Buffer
    : BP to the previous Buffer
    : B3 to buffer 3
    : Bindex.html to the buffer named index.html
    : Save sav ......
    : When sethidden switches to the buffer, no prompt is given to save the current buffer.
    CTRL-G to view the current buffer status information, such as the file name, the total number of rows, not saved after modification.
  2. : SP (: VSP) file name Vim Splits a horizontal (vertical) window and opens a new file in the window. starting from vim6.0, the file name can be a directory name. Open the Directory and display the file list. Press enter on the file name to open the file in this window, if you enter o, open the file in a new window. Enter? You can see the help information.
  3. : E file name Vim will open a new file in the original window. If the old file has been edited, it will be required to save.
  4. C-w (press Ctrl and W together). What should I do if Vim has cut several windows? Enter this command to cyclically locate the cursor in each window. the C-w-H cursor goes to the Left window, the C-w-J lower window, the C-w-K upper window, and the C-W-l right window.
  5. Ls this command shows how many files have been opened in the vim program. The following data is displayed at the bottom of the screen:
    1% a "usevim.html" Row 162
    2 # "xxxxxx.html" line 0
  6. Where: 1 indicates the sequence number of the opened file, which is very useful.
    % A indicates the file code, and % indicates the file being edited,
    # Indicates the Last edited File
    "Usevim.html" indicates the file name.
    Line 162 indicates the cursor position.: B serial number (CODE) This command opens the file with the specified serial number (CODE) in this window, where the serial number (CODE)
    The LS command is used.
  7. : Setdiff this command is used to compare two files. You can use
    : VSP filename
    Command to open another file, and then enter this command in each file window, you can see
    The effect is reached.
Source Address: http://blog.163.com/xinjun_java/blog/static/5118203120076981913266/
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.