Vim Common commands

Source: Internet
Author: User
Tags line editor

First, enter the editor

Line: Edit,e,ex

Screen: Vi,v,view

Vi-r filename (continue the accidental file edit)

VI file1 file2 file3 (after editing the previous file, use: W to save, use: N to start the next file edit)

Vi-x filename (edit to encrypt encrypted file)

Execute Unix command in VI ([[Plus number representing original line] plus R for reading results into VI]!ls)

VI Command line editing function ($set-o VI)

Two, line editor commands

Edit (or E,ex) command

Screen conversion: V (rotary screen), VI (Rotary screen),:(career)

: Wq (save to exit),: Q (Exit),: q! (Forced Exit),: W (Save),: W file (Save As)

: N (moves to n rows),: NP (shows and moves to n rows): M,NP (displays m rows to n rows, moves to n rows),

:d (Display the current line),: ND (delete the nth row, move to n next line),: m,nd (delete the M to nth Row, move to n rows),

: A (starts entering text at the bottom of the current line, until ESC), 1,$ (first line to last line),:., $ (current line to last row)

Example:

: s/stirng1/string2/(replace the first character with the second character)

: M,ns/string1/string2/g (g for all, MN replacement range limited to M rows to n rows)

:%s/string1/string2/g (% represents full text replacement)

Three, vi Basic control command

: Wq (save to exit),: Q (Exit),: q! (Forced Exit),: W (Save),: W file (Save As)

: R filename (after adding the file to the current line)

Cursor movement: Up or DOWN ARROW key, or hjkl,^ (beginning), $ (line end),

+ (Move down one line),-(Move up one line), space (move left), backspace (move right)

Enter edit state: (before cursor), I (at the beginning of the line), a (after the cursor), a (row end), O (add line below), O (add line above), ESC (return to command mode)

Iv. Basic editing commands (operation after exiting from edit state ESC)

Delete text: x (character), DW (word), D (current position to end of line), DD (current line)

Replace text: R (single character), CW (word)

Search text:/(current to tail),? (current head), N (Find Next), N (Find previous one)

Other Commands: U (undo),. (repeat), J (connecting the next migration), P (paste delete content)

Examples of commands: 2dd/p (delete two-line paste), 2yy/p (copy two-line paste)

V. VI Setup Commands

Add line Sequence Number: Set Number,set nonumber

Vi. Set of commands

Insert a string vertically before a paragraph of text

CTRL + V//Vertical block Select the first column of the paragraph

Shirt+i//Insert in front of text

Input string

ESC//Command End

}

Seven, VI Programming skills

Trace header file: GF

View function definition: [+i

Jump to function definition: [+tab

Ctags command

Definition Trace: ctrl+[

Ctrl+o: Trace return

can use CTRL + Z to turn VI into the background, FG can return VI

Make Debug window:

After executing: make, perform CW, window appears

Close the Debug window cclose or Ctrl+w C

. Repeat the last command

Eight, vim folding command

Foreword Preparation:

(1) First ensure that you install the full version of Vim,ubuntu 8.04 is not the full version.

(2) Do not bother to read long articles, enumerate the most useful folding statements.

(3) In Foldmethod=manual state, you can switch to this state by using the: Set foldmethod=manual command.

(4) [email protected] Published, reproduced please indicate the source.

To create a fold:

(1) ZF: Select the statement to fold with the V block, fold with ZF (Z is much like a folded shape, f is fold abbreviation).

(2) Zf[x]j: Fold down x rows, such as zf9j.

(3) You can use the general positioning method to tell vim you want to fold those places: You can also use marker, you can also use the line number: 20, 50, you can put 20 lines to 50 lines fold up.

(4) Convenient folding function: Move to a curly brace {on (or inside the function), with ZFA}, you can fold the contents of the following matching curly braces. Other folding methods also have zf/string, which can be collapsed to the next matching string.

Use folding:

(1) When moving in front of a z can be moved in the folded place, such as ZJ, will jump to the next fold, ZK is the last.

(2) To open the words can be zo,o is open meaning, Zo opened all the folds.

(3) Close with ZC, C is close. With Zc after Zo, all open folds are closed.

(4) folding can be nested, ZR can open the first layer of folding, ZR can open all the folds of the layer, and the corresponding is ZM and ZM, is folded by the layer closed. For example, according to ZM, will be from the innermost layer of the cascade off, continuous ZM will be closed to the top of the fold.

Found collapsed inside will be folded open, after processing, you will fold the folding closed.

Folding Options:

Allows vim to automatically fold according to syntax, indentation, and markup. Set with Set Foldmethod=foldoption. You can check the Foldmethod.

Keep Folding:

(1) To open the next time also keep folding can leave the time: Mkview, and then come in: Loadview on it.

(2) Of course, the two sentences can be added to VIMRC inside to let it complete automatically.

Au Bufwinleave * Mkview

Au bufwinenter * Silent Loadview

So you can see the last folding every time.

Other tips:

: After set foldmethod=manual, Zc presses indent to close all folds

Nine, vim tag command

: Tabnew Open new Tab

Conversion between GT tags

Ten, vim block command

After a block is selected

shift+< left,shift+> Move right

Man help command

Q exit

. The file that starts with is a hidden file

Ls-s

Owner all Groups

chmod Modifying file permissions

Cat file

Mount

CTRL Shift T

Alt 1

Vim Common commands

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.