Vim Reference Manual

Source: Internet
Author: User

Index

    • Jump
    • Undo
    • Code folding
    • Buffer Zone
    • Tag
    • Open and save files
    • Insert
    • Move cursor
    • Copy, paste, and delete
    • Indent
    • Search and replace
    • Bookmarks
    • Ctags
    • Bash
    • Auto-completion
    • Split screen
    • Diff
    • Others

 

Jumps)

The jump command is similar to the <forward> <backward> button in the browser.
CTRL-]-> transfer with Link/Tag (Follow link/Tag)
CTRL-o-> return to the previous jump (go back)
CTRL-I-> jump back to the next (go forward)
: Ju-> Print jump list)

 

Redo/reply

U-> undo
CTRL-r-> redo
Vim's Undo is a tree structure. You can return to any part of this structure.
: Undo 2-> undo to Layer 2 of the structure (undo to tree 2)
: Undolist-> show undo list)
: Earlier 10 s-> undo to 10 seconds ago (undo to 10 seconds ago)
: Earlier 10 h-> undo to 10 hours ago (back to 10 hours ago)
: Earlier 1 m-> undo to 1 minute ago (back to 1 minutes ago)
The following is an explanation of the tree structure of Undo.
........... One
............. |
........ Change 1
............. |
......... One too
.......... /........ \
..... Change 2 ....... Change 3
............ | ..................... |
....... One two .......... Me too
........... |
..... Change 4
........... |
...... Not two

 

CodeFold

1. Folding Mode
You can use the 'foldmethod' option to set the foldmethod:Set OFDM = ***** .
There are 6 Ways to select the fold:
Manual manual definition folding
More indent indicates more fold
Expr uses expressions to define collapse
Syntax uses syntax highlighting to define collapse
Diff folds Unchanged text
Marker folds the mark in the text
Note that each folding method is incompatible. If expr is not used and marker is used, the indent and marker modes are used 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. Fold command
After the folding method is selected, we can implement the folding we need for some code. Because I use more indent and marker, their usage is used 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 folding
ZC folds all nested folding points in the range
Zo unfold and fold
Zo expands all nested folding points in the range
[Z to the start of the current fold.
] 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 of the system is {And}. Do not change it :)
We can use the following command to create and delete a fold:
ZF creates a fold, for example, in the marker mode:
Zf56g: Creates code folding from the current row to 56 rows;
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.

As for VIM code folding, younger brother is also a beginner and only for reference.

 

* Zo opens the current fold
* ZC folding cursor
* Zr opens all fold layers (opens by level)
* ZM folds all layers (by hierarchy)
* Zr open all folding Zn
* ZM fold all Zn
* Zi switch folding and non-folding commands

 

Buffer Zone

* Vim file1 file2 Multiple File Transfer Buffer
*: E filename re-opens the file in Vim.
*: Ls lists all the buffers.
*: N. Edit the next file.
*: BP jumps to the previous buffer.
*: BN jumps to the next buffer.
*: BN jumps to the specified buffer: B3
*: Bd1 deletes the buffer with ID 1.

 

Tag

*: Open a new tab in tabnew.
*: Tabe <File> open the file on the new tab.
* <Ctrl> + Pageup, Pagedown switch tab.
*: Tabnext, tabprev switch tab, Putty can only use this.

 

Open and save the file

*: E <File> open the file.
*: New enew file.
*: W save.
*: Save all WA files.
*: W <File> Save.
*: WQ is saved and exited.
*: Q exits.
*: Exit all QA instances.
*: Q! Force exit.
* ZZ exits vim and saves the document

 

Quick insert

* ESC switch command mode (the distance is too far away. use Ctrl + C instead ).
* I insert mode.
* I insert at the beginning of the current row.
* R replacement mode.
* A is inserted after the cursor.
* A is inserted at the end of the current row.
* O adds a line under the row where the cursor is located and enters the editing mode.
* O adds a line to the cursor. Note that it is in uppercase.
* V visual mode is selected by character.
* V visual mode: select by line.

 

Move cursor

    • H move the cursor left.
    • J. move the cursor down.
    • K move the cursor up.
    • L move the cursor right.
    • Gg moves the cursor to the file header.
    • G move the cursor to the end of the file.
    • # G move the cursor to the specified row #. Example: 5g
    • % 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)
    • FX: move the cursor to the next X of the current row. Obviously, X can be any letter, and you can use; to repeat your previous F command.
    • TX: similar to the preceding command, but it is moved to the left of X. (This is really useful)
    • FX: it is similar to Fx, but you can look back.

 

    • W: Move backward words (How many words are added before the number)
    • B: Move the forward word (How many words are added before the number)
    • E: Move backward to the end of the word
    • Ge: move forward to the end of the word

 

    • 0: move the cursor to the beginning of the current row.
    • ^: Move the cursor to the first letter of the current row.
    • $: Move the cursor to the end of the row.
    • ): Move the cursor to the next sentence.
    • (: Move the cursor to the previous sentence.
    • TX: Search for X in the row to the right and move it there (to the left in uppercase)
    • 33g: Move to the 33rd rows of the file
    • GG: first line of the file
    • G: The end of the file.
    • 33%: 33% of the file
    • H/m/L: the beginning, middle, and end of the screen.
    • ZT/ZZ/ZB: Move the current row to the beginning/center/Bottom of the screen

 

Copy, paste, and delete
    • YY copies the current row to the clipboard.
    • Nyy copies n rows starting from the current row
    • Y ^ Start copying from the file header.
    • Y $ copy to the end of the file.
    • : #, & Y copy # To & line. Example: 4, 5y
    • P paste after the cursor.
    • P paste to the cursor.
    • Dd deletes the current row.
    • D ^ Delete to the beginning of the row.
    • D $ Delete to the end of the row.
    • : #, & D Delete # To & line. Example: 3, 5d
    • D. The current cursor begins to be deleted to the end of the row.
    • NDD deletes n rows backward from the current row
    • D1g delete data from 1st rows to the current row
    • DNG deletes data from row n to the current row
    • DG deletes data from the current row to the last row
    • X deletes 1 character from the backend.
    • NX deletes n characters from the backend
    • X deletes 1 character forward

 

Indent
> Increase indentation.
<Reduce indentation.
= Auto indent.

 

Search and replace

    • /# Search #. Example:/printf
    • ? # Reverse lookup #.
    • N find the next one.
    • N reverse lookup next.
    • : S/old/new/g There is no prompt to replace the current row.
    • : % S/old/new/g no replacement prompt.
    • : % S/old/new/GC confirm replacement.
    • : #, & S/old/new/g from # To & line No prompt to replace.
    • * Find the word with the cursor

 

Jump to bookmarks

*: Marks to view all bookmarks. Enter ": <num>" to jump.
* M <Name> defines bookmarks. For example, Ma defines bookmarks named a in the current row.
* '<Name> jump to a bookmarks.' is the first key on the keyboard tab.
*: Jumps to view all jump records. Enter ": <num>" to jump.
* <Ctrl> + O returns the previous jump.
* <Ctrl> + I and <Ctrl> + O reverse rotation.

 

Ctags

*:! Ctags-R. Generate the ctags file.
* <Ctrl> +] view the function definition.
* <Ctrl> + t return.
* SHIFT + k to view the man help information of the function.

 

 

CMD

*! <Command> run the command.
*: R <File> inserts the file content.
*: R! <Command> INSERT command output result.
*: CD <path> modifies the default working directory.

 

Auto-completion

CTRL + x Ctrl + L full line completion

CTRL + x Ctrl + n fill in the current file based on the keyword

CTRL + x Ctrl + k complement the dictionary

CTRL + x Ctrl + T complete the dictionary based on the synonym

CTRL + x Ctrl + I fill in according to the keyword in the header file

CTRL + x Ctrl +] complete by tag

CTRL + x Ctrl + f Fill in the file name

CTRL + x Ctrl + D complete macro definition

CTRL + x Ctrl + V complete Vim command

CTRL + x Ctrl + u custom completion Mode

CTRL + x Ctrl + S spelling suggestions

 

Split screen

Start Vim for split screen. Note: N is a number, which indicates several screens.

Vim-on file1 file2... Use the uppercase o parameter to split the screen vertically.

Vim-on file1 file2... Use the lower-case o parameter to split the screen horizontally.

CTRL + w c close split screen close current window.

CTRL + w Q close the current window. If only the last one is left, exit Vim

Split screen

CTRL + w s split up and down the currently opened files.

: SP filename is divided up and down, and a new file is opened.

CTRL + w v: Separate the currently opened files.

: The VSP filename is left and right separated and a new file is opened.

Move the cursor key H, J, K, L in VI. to switch between screens, just press Ctrl + W.

CTRL + w l move the cursor to the screen on the right.

CTRL + w h move the cursor to the screen on the left.

CTRL + w k move the cursor to the screen above.

CTRL + w j move the cursor to the screen below.

CTRL + W move the cursor to the next screen ..

The mobile split screen function still uses the vim optical key, which is only capitalized. Of course, if your split screen is messy and complicated, this function may have some very strange symptoms.

CTRL + w l move to the right.

CTRL + w h move to left

CTRL + w k move up

CTRL + w j move down

Below are some operations for changing the screen size, mainly the height. You can use Ctrl + W <or> for the width, but this may be supported by the latest version.

CTRL + W = make all the screens have the same height.

CTRL + W + increase the height.

CTRL + w-Reduce height.

CTRL + W> extend to the right

CTRL + W <extend to left

 

Diff Mode

Reference

Compare the files a and B, VIM-d a B, or

Or open file a first, and then: VSP(Vsplit in full name) open B and enter the command: Diffthis

OrVimdiff file_left file_right

] C jump to the next difference

[C reverse jump

 

Context folding reference

By default, vimdiff folds and hides the same text except the last six lines in the file. You can use: Set diffopt = context: 3 to modify the number of displayed context lines.

Zo hide

ZC hide

File Merging

DP copies the content at the cursor position of the current window to another window.

Do copies the content at the cursor position of another window to the current window.

Diffupdate: recompares two files. If you manually modify the files, the files are not automatically synchronized.

 

 

 

Others

Gg = g source code format

: E! Force re-edit
Shift insert copy from system to VIM
U undo the previous operation.
U undo the operation on the last modified row
*. Redo.

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.