Vim common cmds:

Source: Internet
Author: User
Tags line editor

Neonlight@live.cn published, reproduced please indicate the source.

Common cmds:
% Jump to matching brackets
[[Jump to the beginning of the code block (but the '{' in the code block must be a separate line)
GD jump to the definition of a local variable
''Jump to the position where the cursor was stopped last time. It's two '', not one"
MX sets bookmarks. X can only contain 26 letters in a-Z.
'X' jump to the bookmarks ("'" is the key on the left of 1)
> Add indentation. "x>" indicates adding the indentation of the following X rows.
<Reduce indentation, "x <" indicates reducing indentation of the following X rows

1. Go to the editor
Row: Edit, E, ex
Screen: VI, V, View
VI-r filename)
VI file1 file2 file3 (after editing the previous file, save it with W and start editing the next file with N)
VI-x filename (edit the encrypt encrypted file)
Run the Unix Command in VI ([Add a number to indicate the first few lines] add r to read the result into VI]! Ls)
VI command line editing function ($ set-o vi)

2. Line Editor commands
Edit (or E, ex) command
Screen Editing and conversion: V (screen editing), VI (screen editing), (just click it)
: WQ (Disk logout),: Q (logout),: Q! (Force exit), w (SAVE), w file (Save)
: N (move to N rows),: Np (show and move to N rows),: M, NP (show m rows to N rows of content, move to N rows ),
: D (display current row),: Nd (Delete row N content, move to row N),: M, Nd (Delete row m to row N, move to N rows ),
: A (Enter text in the row that moves down the current row until ESC), 1, $ (the first row to the last row),:., $ (the current row to the last row)

Example:
: S/stirng1/string2/(Replace the first character with the second character)
: M, NS/string1/string2/g (G indicates all, Mn replacement range is limited to m rows to N rows)
: % S/string1/string2/g (% indicates full text replacement)

Iii. VI Basic control commands
: WQ (Disk logout),: Q (logout),: Q! (Force exit), w (SAVE), w file (Save)
: R filename (add the file to the current row)
Move the cursor: move the cursor up or down to the left or right direction key, or hjkl, ^ (first row), $ (last row ),
+ (Move one row down),-(move one row up), Space (move left), and return (move right)
Enter the edit State: (before the cursor), I (First row), A (after the cursor), A (last row), O (add row below), O (add row above ), ESC (return command mode)

Iv. VI Basic editing commands
Delete text: X (character), DW (Word), D (current position to the end of the line), DD (current row)
Replace text: R (single character), CW (word)
Search Text:/(current to the end ),? (Current direction), n (find next), n (find previous)
Other commands: U (UNDO),. (Repeat), J (move row down), P (paste the deleted content)

Command example: 2dd/P (delete two lines), 2yy/P (copy and paste two lines)

V. VI setting commands
Add row number: set number, set nonumber

VI set commands
Insert a string vertically before a text clip.
{
CTRL + V // the first column of the selected section in vertical parts
Shirt + I // Insert before text
Input string
ESC // command end
}

VII. VI programming skills
Tracking header file: GF
View the Function Definition: [+ I
Jump to function definition: [+ Tab
Ctags command
Definition tracking: Ctrl + [
CTRL + O: trace return

You can use Ctrl + Z to transfer VI to the background, and FG can return vi
Make debugging window:
After: Make is executed, run CW. The window appears.
Close the debugging window cClose or Ctrl + W C

. Repeat the previous command

8. Vim folding command
Preface:
(1) first, make sure that you have installed the full version Vim. Ubuntu 8.04 does not come with the full version.
(2) read long articles and list the most practical collapse statements.
(3) run the command in the foldmethod = manual state. You can use the: Set foldmethod = manual command to switch to this state.
(4) neonlight@live.cn published, reprint please indicate the source.

Create fold:
(1) ZF: Use V to select the statement to be folded, and use ZF to fold (Z is similar to fold, and F is the abbreviation of fold ).
(2) ZF [x] J: Collapse x rows down, for example, zf9j.
(3) You can use the general positioning method to tell Vim where you want to fold: You can also use marker, or the row number: 20, 50, you can fold 20 to 50 rows.
(4) Easy-to-fold function: Move to a curly braces {(or function body), use zfa }, you can fold the following matching curly braces. Other folding methods include ZF/string, which can be folded to the next matched string.

Fold:
(1) When moving, add a Z in front to move in the fold area. For example, ZJ will jump to the next fold, and zk will be the last one.
(2) to open it, Zo and O are the meaning of open. Zo opens all folds.
(3) Use ZC to close and C to close. After Zo, ZC will close all opened folds.
(4) folding can be nested. Zr can open the folding of the first layer. Zr can open the folding of all layers. ZM and ZM correspond to the folding of layers. For example, if you press ZM, it will start from the layer at the bottom, and the continuous ZM will continue to the fold at the top.

If you find the fold, it will be folded and closed.

Folding options:
Enable Vim to indent and Mark automatic folding according to the syntax. Set with set foldmethod = foldoption. You can check the foldmethod.

Reserved folding:
(1) The next time you open it, you can still fold it. When you exit: mkview, and when you come in: loadview.
(2) Of course, you can add these two sentences to vimrc for Automatic completion.
AU bufwinleave * mkview
AU bufwinenter * silent loadview
In this way, we can see the previous fold every time.

Other tips:
: Set foldmethod = manual, ZC closes all folds by indentation

Vim folding settings supplement: (reprinted)

Set foldmethod = indent "Set Default foldmethod" Zi open close fold "ZV view this row ZM close fold ZM close all Zr open all ZC fold current row Zo open current fold ZD Delete fold ZD delete all folds 1. the foldmethod option can be used to set the foldmethod: Set OFDM = *****. There are 6 Ways to select the fold: manual manual definition folding indent more indentation representation higher level folding expr use expressions to define folding syntax use syntax highlighting to define folding diff for Unchanged text folding marker for text flag fold note, each folding method is incompatible. If expr is not available and marker is used, I use indent and marker in turn. When using this function, use the: Set OFDM = marker command to set it to the marker foldmethod ). To make the folding take effect every time Vim is opened, add the settings in the. vimrc file, such as adding: Set OFDM = syntax, just like adding other initialization settings. 2. after the folding method is selected for the folding command, we can implement the folding that we need for some code. Because I use indent and marker a little more, we use them as an example: if the indent method is used, VIM automatically folds the middle part of the braces, and we can directly use these ready-made folding results. In a foldable place (in the middle of braces ): ZC fold all nested folding points in the range Zo unfold fold Zo unfold all nested folding points in the range [Z to the start of the current folding.] Z to the end of the currently opened fold. ZJ moves down. To the start of the next fold. The closed folding is also included. ZK moves up to the end of the previous fold. The closed folding is also included. When using the marker method, you need to use a tag to identify code folding. The default value is {And }}}, do not change it :) we can use the following command to create and delete the fold: ZF create fold, for example, in the marker mode: zf56g, create a code fold from the current row to 56 lines; 10zf, 10zf +, or zf10 labels, create code folding from the current row to the last 10 lines. 10zf-or zf10 labels, create code folding from the current row to the previous 10 lines. At ZF %, create the matching brackets (), {}, [], <>, etc.) from the current row ). ZD Delete is the folding of the cursor. Valid only when 'foldmethod' is set to "Manual" or "marker. ZD loop Delete refers to the folding under the cursor, that is, nesting Delete fold. Valid only when 'foldmethod' is set to "Manual" or "marker. Ze removes all folds in the (eliminate) window. Valid only when 'foldmethod' is set to "Manual" or "marker. Use Vim's folding function to write program code folding: 2. Create a line to preview the outline. 2. Move it to a certain place and edit it. 2. Use jzij to open the text. 2. After editing, use jzij to open the line. Open the vim fold function. Go ~ /. Add set foldmethod = marker to vimrc and use Vim's default folding label for processing. Use the following method: 1. In normal mode, enter ZF on the keyboard and press Enter. Then, you will see the labels of the two lines collapsed as follows: /*{{{*/..... enter your program code/* }}} */2. Enter the program code and fold the code to use the following command (normal mode ): ZC press Enter 3. The folding program has the following methods: A. move the cursor B on the collapsed line, enter Zo in normal mode, and press ENTER 4. Fold a text line (normal mode) the zfap5 AND Zr commands enable ZM to fold several layers of content and use more (this can be used repeatedly during multi-layer folding ). 6. multiple layers of lines are nested. You can also use the Zr command to open all lines at a time. 7. Close all nested lines. Use zm8. You can use the jznj command to disable one line. then jznj can be used to restore it. the jzij command can be switched between the two. for more information, see the vim user manual. When checking the Code, if the code is very lengthy, especially in the C/C ++ series, it is difficult to clarify the code structure, it is mainly about the matching of comments and parentheses. Although you can use % to check where the other half of the matching symbols are, if the code between these symbols exceeds one page, it is hard to understand even several pages. Therefore, we can use the folding feature provided by VIM to simplify the analysis. The Vim I use is a built-in version of rh9. Fold mode: vim provides the folding mode in "6" manual definition folding indent more indent represents more advanced folding expr use expressions to define folding syntax use syntax highlighting to define folding diff for Unchanged text the folding marker option 'foldmethod' can be used to set the folding mode for the logo folding in the text: set OFDM = *****. Note that each folding method is incompatible, that is, you cannot use expr or marker. Currently, I usually use more indent instances. Use the: Set OFDM = indent command to set the marker folding mode. Add settings in the. vimrc file to enable the folding mode for each opened VI. For example, add set OFDM = syntax. 2. After the folding mode is selected for opening and folding, we can implement the folding mode we need for some code. If the indent method is used, VIM automatically folds the middle part of the braces, and we can directly use these ready-made folding results. The folding code corresponding to indent is: ZC fold all nested folding points in the range Zo unfold fold Zo unfold all nested folding points in the range [Z to the start of the current folding.] Z to the end of the currently opened fold. ZJ moves down. To the start of the next fold. The closed folding is also included. ZK moves up to the end of the previous fold. The closed folding is also included. Enter the preceding command in braces for use. When using the marker method, you need to use a tag to identify code folding. The default value is {And }}}, do not change it :) you can use the following command to create and delete the fold: ZF create fold, for example, in the marker mode: zf56g, create a code fold from the current row to 56 lines; 10zf, 10zf +, or zf10 labels, create code folding from the current row to the last 10 lines. 10zf-or zf10 labels, create code folding from the current row to the previous 10 lines. At ZF %, create the matching brackets (), {}, [], <>, etc.) from the current row ). ZD Delete is the folding of the cursor. Valid only when 'foldmethod' is set to "Manual" or "marker. ZD loop Delete refers to the folding under the cursor, that is, nesting Delete fold. Valid only when 'foldmethod' is set to "Manual" or "marker. Ze removes all folds in the (eliminate) window. Valid only when 'foldmethod' is set to "Manual" or "marker.

IX. Vim label command

: Tabnew open new tag

GT tag Conversion

10. Vim block selection command

After the selected block

Shift + <shift to left, Shift +> shift to right

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.