Vim commands and vim commands

Source: Internet
Author: User

Vim commands and vim commands

1. About Vim

Vim is my favorite editor and the second most powerful editor in Linux. Although emacs is recognized as the world's No. 1, I think it is more efficient to use emacs without using vi for editing. If you are a beginner, running vimtutor is a smart decision. (If your system environment is not Chinese and you want to use a Chinese vimtutor, run vimtutor zh)

1.1 several Vim Modes

Normal Mode: You can use the shortcut key command or press: Enter command line. Insert mode: You can enter text. In normal mode, press I, a, o, and so on to enter the insert mode. Visual mode: In normal mode, press v to enter the visual mode. In visual mode, move the cursor to select text. Press V to enter the visible line mode. The entire row is always selected. Ctrl + v enter the visual block mode. Replacement mode: In normal mode, press R to enter.

2. Start Vim

Vim-c cmd file: Execute the specified command before opening the file; vim-r file: Restore the file that exited with the last exception; vim-R file: open the file in read-only mode, but it can be forcibly saved; vim-M file: open the file in read-only mode, cannot be forcibly saved; vim-y num file: set the size of the edit window to num row; vim + file: starting from the end of the file; vim + num file: Starting from row num; vim +/string file: Opening file, and place the cursor on the first string to be found. Vim-remote file: use an existing vim process to open a specified file. This is useful if you do not want to enable multiple vim sessions. However, if you use vim, you will find a server named VIM. If you already have gvim running, you can use gvim-remote file to open a file in an existing gvim file.

3. Document operations

: E file-close the currently edited file and enable the new file. If the changes to the current file are not saved, vi will warn. : E! File-Discard modification to the current file and edit the new file. : E + file-start a new file and start editing from the end of the file. : E + n file-start the new file and start editing from line n. : Enew-compile an unnamed new document. (CTRL-W n): e-Reload the current document. : E! -Reload the current document and discard the changes. : E # or ctrl + ^-Return to the edited file, which is very practical. : F or ctrl + g-display document name, whether to modify, and cursor position. : F filename-change the edited file name, and then save it as save. Gf-open the file named after the string where the cursor is located. : W-Save the modification. : N1, n2w filename-selectively stores content from a n1 row to another n2 row. : Wq-Save and exit. ZZ-Save and exit. : X-Save and exit. : Q [uit] -- exit the current window. (CTRL-W q or CTRL-W CTRL-Q): saveas newfilename-Save As: browse e-opens a file browser asking you to select the file to edit. If it is in the terminal, the netrw file browsing window will be opened; if it is gvim, a GUI browsing window will be opened. In fact, browse can be followed by any command to edit the document, such as sp. The START directory opened with browse can be set by browsedir: set browsedir = last-use the last accessed directory (default);: set browsedir = buffer-use the directory where the current file is located;: set browsedir = current-use the current working directory;: Sex-split a window horizontally to browse the file system;: Vex-split a window vertically to browse the file system;

4. move the cursor

4.1 basic mobile

The following moves are in normal mode.

H or return space: move one character to the left; l or space: move one character to the right; j: move one line down; k: move one line up; gj: Move to the next line within a segment; gk: + or Enter: move the cursor to the first non-blank character in the next line. -: Move the cursor to the first non-blank character in the previous line. W: Move a word forward, the cursor stops at the beginning of the next word; W: Move the start of the next word, but ignore some punctuation; e: Move a word forward, the cursor stops at the end of the next word; E: move to the end of the next word. If there is a Punctuation Point at the end of the word, move it to the Punctuation Point. B: move the cursor to the beginning of the previous word. B: Move it to the beginning of the previous word to ignore some punctuation points; ge: Move a word behind, and the cursor stops at the end of the previous word. gE: Same as ge, but 'word' contains adjacent punctuation. (: Move one sentence forward .) : Move one sentence behind. {: Forward 1 segment .} : Move 1 segment behind. Fc: move the cursor to the next c character in the same row Fc: move the cursor to the previous c character in the same row tc: move the cursor to the beginning of the next c character in the same row Tc: move the cursor to the previous c character of the same row;: used with f & t, repeat once;: used with f & t, repeat once in reverse

The preceding operations can be used with n. For example, if you enter 3 h in normal mode (as described below), the cursor is moved three characters to the left.

0: Move to the beginning of the row. G0: move the cursor to the beginning of the line of the screen. ^: Move to the first non-blank character in the row. G ^: Same as ^, but moved to the first non-null character in the current screen line. : Move to the end of the row. G "role =" presentation "style =" position: relative; ">: Move to the end of the row. G: Move to the end of the row. G: move the cursor at the end of the row of the screen. N |: move the cursor to the n column. NG: the nth line of the file. : N moves to row n. : $ Move to the last row. H: move the cursor to the top row of the screen. M: move the cursor to the middle line of the screen. L: move the cursor to the bottom of the screen. Gg: To the file header. G: to the end of the file.

4.2 screen flip

Ctrl + f: Flip the screen. Ctrl + B: Flip the screen. Ctrl + d: half screen flip. Ctrl + u: half screen flip. Ctrl + e: Scroll down a row. Ctrl + y: Scroll up a row. N %: Path to file n %. Zz: Move the current row to the center of the screen. Zt: Move the current row to the top of the screen. Zb: Move the current row to the bottom of the screen.

4.3 mark

You can use tags to move quickly. After the mark is reached, you can use Ctrl + o to return the original position. Ctrl + o and Ctrl + I are similar to the back and forward of the browser.

M {a-z}: Mark the position of the cursor, partial mark, used only for the current file. M {A-Z}: marking the position of the cursor, global marking. After the tag is marked, exit Vim and restart. The tag is still valid. '{A-z}: Move to the tag location. '{A-z}: Move to the beginning of the row marking. '{0-9}: Return to the Last Exit position when vim is disabled for [2-10] times. ": Move to the Last edited location ." Yes, but "accurate to columns" is accurate to rows. If you want to jump to an older position, you can press C-o to switch to the updated position using C-I. '": Move to the last place you left. '.: Move to the last modification. : Marks: displays all tags. : Delmarks a B-delete tags a and B. : Delmarks a-c-delete tags a, B, and c. : Delmarks a c-f-delete tags a, c, d, e, and f. : Delmarks! -Delete All tags of the current buffer. : Help mark-motions View

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.