From here,

1. About Vim

Vim is my favorite editor and the second most powerful on Linux. Although Emacs is recognized as the best in the world, I don’t think using Emacs is as efficient as using VI for editing. If you’re new to VI, it’s a smart decision to run vimTutor. (If your system environment is not Chinese and you want to use Chinese vimTutor, run VimTutor zh)

1.1 Several modes of Vim

Normal mode: You can use the shortcut key to run a command, or press: to enter a command line. Insert mode: You can enter text. In normal mode, press I, A, or O to enter the insert mode. Visual mode: Press V in normal mode to enter visual mode. In visual mode, move the cursor to select text. Press V to enter visual line mode, always full line selection. CTRL + V to enter visible block mode, then use j/ K/H/L to select block replacement mode: in normal mode, press R to enter.

2. Start the Vim

Vim -c CMD file: Run the specified command before opening the file. Vim -r file: restores the file that was abnormally exited last time. Vim -r file: opens a file in read-only mode but can be forcibly saved. Vim -m file: the file is opened in read-only mode and cannot be forcibly saved. Vim -y num file: Set the size of the edit window to num lines; Vim + file: start at the end of the file; Vim +num file: start at line num; Vim +/string file: Open file and hover the cursor over the first string found. Vim –remote file: Use the existing Vim process to open the specified file. This is useful if you don’t want to enable multiple VIM sessions. But be aware that if you use Vim, you’ll be looking for a server named Vim; If you already have a gvim running, you can use gvim –remote File to open files in your existing Gvim.

3. Document operations

:e file — Closes the currently edited file and opens a new one. Vi warns if changes to the current file are not saved. :e! File – Discard changes to the current file and edit a new file. :e+file — Start a new file and edit from the end of the file. :e+n file — Starts a new file and edits from line NTH. :enew – Compiles a new unnamed document. (Ctrl-w n) :e — Reload the current document. :e! Reload the current document and discard the changes. :e# or CTRL +^ — go back to the file you just edited, useful. :f or CTRL + G — displays the document name, whether to modify, and cursor position. :f filename — Changes the name of the edited file, saving it again is equivalent to saving as. Gf — Opens the file named in the string where the cursor is located. :w — Save the changes. :n1,n2w filename — Optionally saves the contents from one n1 line to another n2 line. :wq — Save and exit. ZZ — Save and exit. šŸ˜” — Save and exit. :q[uit] — Exits the current window. (ctrl-w q or ctrl-w ctrl-q) :saveas newfilename — saveas :browse e — opens a file browser that lets you select the file to edit. If it is a terminal, it will open the netrW file browsing window; In the case of Gvim, a graphical browsing window opens. Actually: Browse can be followed by any command to edit the document, such as sp, etc. The starting directory opened with Browse can be set by Browsedir: :set browsedir=last — use the directory last accessed (default); :set browsedir=buffer — use the current file directory; :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. Cursor movement

4.1 Basic Movement

The following moves are in normal mode.

H or backspace: moved one character to the left; L or space: move one character to the right; J: Move down one line; K: Move up one line; Gj: Move to the next line of a paragraph; Gk: to move to the previous line of a paragraph; + or Enter: moves the cursor to the first non-white space character on the next line. -: Moves the cursor to the first non-white space character on the previous line. W: Move one word forward and the cursor stops at the beginning of the next word. W: Move the beginning of the next word, but ignore some punctuation; E: Move one word forward and the cursor stops at the end of the next word. E: Move to the end of the next word, if there is punctuation at the end, move to punctuation; B: Move the cursor back one word to the beginning of the previous word. B: Move to the beginning of the previous word and ignore some punctuation; Ge: Move one word backward, placing the cursor at the end of the previous word; GE: same as gE, except that ‘word’ contains punctuation marks adjacent to words. (: move forward 1 sentence.) : Move back 1 sentence. {: move forward 1. }: move back 1 paragraph. Fc: Move the cursor to the next C character on the same line fc: move the cursor to the next C character on the same line TC: Move the cursor to the next C character on the same line TC: Move the cursor to the next C character on the same line. : Used with f & T, repeat once, such as after FA, then; Fa,: is used with f & t. Repeat the above operations in reverse with N. For example, if you enter 3h in normal mode (as described below), the cursor moves 3 characters to the left.

0: moves to the top of the line. G0: Move to the beginning of the line on the screen where the cursor is. ^: Moves to the first non-whitespace character on the line. G ^: same as ^, but moved to the first non-null character on the current screen line. : moves to the end of the line. G: Move to the end of the line. G: Move to the end of the line. G: Move the cursor to the end of the screen. N | : move the cursor to give n columns. NG: line n of the file. :n moves to line n. :$moves to the last line. H: Move the cursor to the top line of the screen. M: Move the cursor to the middle line of the screen. L: Move the cursor to the bottom line of the screen. Gg: to the file header. G: To the end of the file.

4.2 double screen

CTRL + F: Scroll down one screen. CTRL + B: Scroll up one screen. CTRL + D: Scroll down half screen. CTRL + U: Scroll up half screen. CTRL + E: Scroll down one line. CTRL + Y: Scroll up one line. N %: to file n% location. Zz: Moves the current row to the center of the screen. Zt: Moves the current line to the top of the screen. Zb: Moves the current line to the bottom of the screen.

4.3 mark

Use tags to move quickly. Once you reach the mark, you can press Ctrl+ O to return to the original position. Ctrl+ O and Ctrl+ I are very much like back and forward on the browser.

M {a-z}: marks the position of the cursor, local marks, only for the current file. M {a-z}: marks the position of the cursor, global mark. After marking, exit Vim, restart, and the marking is still valid. {a-z}: Move to the marked position. ‘{a-z}: moves to the beginning of the marked line. {0-9} : Return to the last position left when vim was closed [2-10] times before. : Moves to the position of the last edit. “Is fine, but it’s down to the column, and” is down to the row. To jump to an older location, press C-O. To jump to a newer location, use C-I. “: Move to the place you left last time. .: Move to the last change. :marks displays all tags. :delmarks a b — removes the tags A and b. :delmarks A-c — Removes the tags A, B, and C. :delmarks a c-f — delete the marks A, c, d, e, f. :delmarks! — Removes all tokens from the current buffer. : Help Mark-motions see more about Mark.

5. Insert text

5.1 Basic Insertion

I: Insert before cursor; A quick tip: Press 8, then I to enter insert mode, type =, press Esc to enter command mode, and 8 = will appear. This is useful when inserting dividers, such as 30i+, which inserts 36 + dividers. I: insert before the first non-null character on the current line; GI: inserts in the first column of the current row; A: Insert after the cursor; A: Insert at the end of the current line; O: Insert a new line below; O: Insert a new line above it. :r filename Inserts the contents of another file at the current location. :[n]r filename Inserts the contents of another file at line n. :r ! Date Inserts the current date and time at the cursor. Similarly, :r! Command can insert the output of other shell commands into the current document.

5.2 Overwrite Insert

C [n]w: Rewrite 1(n) word after the cursor. C [n] L: Rewrites the n letters after the cursor. C [n]h: Rewrites n letters before the cursor. [n]cc: modifies the current [n] line. [n]s: Replaces the 1(n) character after the cursor with the input text, equivalent to C [n] L. [n]S: Deletes a specified number of lines and replaces them with the entered text. Note that forms like CNW, DNW and ynw can also be written as NCW, NDW and nyw.

6. Cut copy and register

6.1 Cut, Copy, and Paste

[n]x: cut n characters to the right of the cursor, equivalent to D [n] L. [n]X: cut n characters to the left of the cursor, equivalent to D [n]h. Y: Copies the text selected in visual mode. Yy or Y: Copy the entire line of text. Y [n]w: Copy one (n) word. Y [n] L: Copies 1(n) character to the right of the cursor. Y [n]h: Copies 1(n) character to the left of the cursor. Y: copies the cursor from the current position to the end of the line. Y0: copies from the current cursor position to the beginning of the line. :m,ny

copies the contents of lines M to n. Y1G or YGG: Copies all lines above the cursor. YG: Copies all lines below the cursor. Yaw and Yas: Copy a word and a sentence, even if the cursor is not at the beginning of the word and sentence. D: Deletes (cuts) the selected text in visual mode. D: Copies from the current cursor position to the end of the line. Y0: copies from the current cursor position to the beginning of the line. :m,ny

copies the contents of lines M to n. Y1G or YGG: Copies all lines above the cursor. YG: Copies all lines below the cursor. Yaw and Yas: Copy a word and a sentence, even if the cursor is not at the beginning of the word and sentence. D: Deletes (cuts) the selected text in visual mode. D: Copies from the current cursor position to the end of the line. Y0: copies from the current cursor position to the beginning of the line. :m,ny

copies the contents of lines M to n. Y1G or YGG: Copies all lines above the cursor. YG: Copies all lines below the cursor. Yaw and Yas: Copy a word and a sentence, even if the cursor is not at the beginning of the word and sentence. D: Deletes (cuts) the selected text in visual mode. D or D: Deletes (cuts) the current position to the end of the line. D [n] W: delete (cut) 1(n) word D [n] L: delete (cut) 1(n) character to the right of cursor. D [n]h: Deletes (cuts) 1(n) character left of the cursor. D0: delete (cut) the current position to the beginning of the line [n] DD: delete (cut) 1(n) line. :m,nd Cut lines m to N. D1G or DGG: Cut all lines above the cursor. DG: Cut all lines below the cursor. Daw and DAS: Cut a word and a sentence, even if the cursor is not at the beginning of the word and sentence. Dt character — deletes this line until the first specified character [excluding this character] df character — deletes this line until the first specified character [excluding this character] p is encountered: pastes after the cursor. P: Paste before the cursor.


6.2 Text Objects

Aw: One word as one sentence. Ap: A paragraph. Ab: block (enclosed in parentheses). Y, D, c, v can all be associated with text objects.

6.3 register

A-z: can be used as register names. Ayy puts the contents of the current line into register A. A-z: Index registers with uppercase letters. You can append contents to registers. As in “Ayy appends the contents of the current line to register A. :reg displays the contents of all registers. “” : indicates the register used by default when no register index is added. “* : current selection buffer, “* YY puts the contents of the current line into the current selection buffer. “+ : system clipboard. + YY puts the current line into the system clipboard.

7. Find and replace

##7.1 Find /something: Find something in the text that follows. ? Something: Find something in the previous text. /pattern/+number: Place the cursor on the number line following the line containing pattern. /pattern/-number: Place the cursor on the number line before the line containing pattern. N: Go back to the next one. N: Move on to the next one. Grep or vimgrep can be used to find where a pattern has appeared, where :grep is to call the external grep program, and :vimgrep is Vim’s own search algorithm. :vim[grep]/pattern/[g] [j] files g Indicates that if a pattern appears multiple times in a line, the line also appears multiple times in the result. J means that after grep, the result stops at the JTH item. By default, it stops at the first item. Vimgrep can be preceded by a number to limit the upper limit of the search results, such as 1vim/pattern/ % to find only the first occurrence of that pattern in the file. In fact, vimgrep is especially useful when reading plain text ebooks, generating navigable directories. For example, the title of each section in an e-book is n. XXXX. You can do this :vim/^d{1,}./ % and then use :cw or :copen to see the result. You can use c-w H to move the Quickfix window to the left to look more like a directory.

7.2 replace

:s/old/new – Replaces the first old in the current line with new. :s/old/new/g – Replaces all old in the current line with new. :n1,n2s/old/new/g – Replace all old from lines n1 to n2 of file with new. :%s/old/new/g – Replace all old in the file with new. :%s/^/ XXX /g – Insert XXX at the beginning of each line, ^ to indicate the beginning of the line. / XXX /g – Insert XXX at the end of each line. / XXX /gāˆ’ Insert XXX at the end of each line, indicating the end of the line. Add c to the end of all replacement commands, and each replacement will require user confirmation. For example: %s/old/new/gc, plus I, ignore case. A more flexible approach than substitution is to execute a command that matches a pattern,

The syntax is :[range]g/pattern/command For example, %g/^ xyz/normal DD. Indicates to run the dd command in normal mode for lines starting with a space and xyz. Range: If range is not specified, it indicates the current line. M,n: lines from m to N. 0: the first line (possibly). $: last line.: current line %: all lines

7.3 Regular Expressions

Advanced search and replace uses regular expressions. \ d: it means the decimal number \ s: (I guess) for space \ s: not null character \ a: English letters | : said. Or: said. {m, n} : said m to n characters. This is used with \s and \ A, for example \ A {m,n} denotes m to N letters. {m,}: indicates m to infinitely many characters. **: all subdirectories in the current directory. Get more help.

8. Typesetting

8.1 Basic Layout

<< Indent a shiftwidth left

Indent shiftwidth to the right

:ce(nter) Center :le(ft) Left: RI (GHT) Right gq rearrange the selected text, That is, break the text that is too long. GQQ rearranges the current line GQNQ rearranges the current line GQNQ rearranges the current line GqAP rearranges the current line gqNAP rearranges the current line and the following N lines GQQ rearranges the current line and the next line gJ with J at the end of the article, but leaves no space after merging.

8.2 Spelling Check

]s- moves to the next misspelled word [s- works like the previous command but searches in the opposite direction z=- displays a list of misspelled words Zg – tells the spell checker the word is spelled correctly zW – Tells the spell checker the word is misspelled, as opposed to the previous command

8.3 Word Count

G ^g can count the number of characters and lines in a document. Place the cursor on the last character and subtract the number of lines from the number of characters to get a rough count of the word count of the Chinese document. The above applies to Mac or Unix file formats. If the file format is Windows (that is, the newline has two bytes), the count method is as follows: number of characters – number of lines x 2.

9. Edit multiple files

9.1 Editing Multiple Files at a time

We can open more than one file at a time, such as

Vi a.testt b.testt c.testt edit the next file using :next(:n). :2n Edit the next two files. Edit the previous file with :previous or :N. Using :wnext, save the current file and edit the next file. Save the current file and edit the previous file using :wprevious. Use :args to display the file list. :n filenames or :args filenames Specifies a new file list. Vi-o Filenames edits multiple files in horizontally split Windows. Vi-o Filenames edits multiple files in vertically split Windows.

9.2 Multi-label Editing

Vim -p Files: Open multiple files, each file occupies a TAB page. :tabe, tabNew — open the file in a new TAB if the file name is added, otherwise an empty buffer is opened. WGF – Opens the file specified in the path under the cursor in a new TAB. :tabn — Switches to the next TAB. Control plus PageDown, you can do that. :tabp — switches to the previous TAB. Control + PageUp, ok. [n] gt — Switch to the next TAB. If n is added, switch to the NTH TAB. The number of the first tag is 1. GT — Switch to the previous one. : TAB split — Opens the contents of the current buffer in a new TAB. :tabc[lose] — closes the current TAB. :tabo[nly] – close other tabs. :tabs — Lists all the tabs and the Windows they contain. :tabm[ove] [N] — Move the TAB after the NTH TAB. If tabm 0 is the current TAB, it becomes the first TAB.

9.3 the buffer

:buffers or :ls or :files displays a list of buffers. CTRL +^ : Toggles between the last two buffers. :bn — the next buffer. :bp — the last buffer. :bl — The last buffer. :b[n] or :[n]b — switches to the NTH buffer. : NBW (iPEout) — deletes the NTH buffer completely. : NBD (elete) — Removes the NTH buffer, not really deleted, still in the unlisted list. :ba[ll] — opens all buffers on the current page, one window for each buffer.

10. Split-screen editing

Vim -o file1 file2: opens file1 and file2 simultaneously in the horizontal partition window vim -o file1 file2: opens file1 and file2 simultaneously in the vertical partition window

10.1 Horizontal segmentation

:split(:sp) — Split the current window horizontally into two Windows. (Ctrl-w S or Ctrl-W Ctrl-s) Note if under terminal, Ctrl-S may freeze terminal, press Ctrl-Q to continue. To make the split window scroll at the same time, type in both Windows: Set SCB :split filename — Split the window horizontally and display another file in a new window. :nsplit(: NSP) — split a window horizontally n lines high. :[N]new — Split a window horizontally N lines high and edit a new file. (Ctrl-w n or Ctrl-W Ctrl-n) CTRL + W F — Split a window horizontally and open a file named the word with the cursor in the new window. C-w C-^ — Split a window horizontally to open the file you just edited.

10.2 Vertical Segmentation

:vsplit(: VSP) – Splits the current window into two horizontally distributed Windows. (Ctrl-w V or CTRL Ctrl-V) :[N]vne[W] — Split a new window vertically. :vertical: indicates the vertical partition command.

10.3 Closing subWindows

:qall — Close all Windows and exit vim. :wall — Save all modified Windows. :only — Keep only the current window and close all other Windows. (Ctrl-w o) :close — Close the current window. Ctrl-w C does the same. (Like: Q šŸ˜” also works)

10.4 Resize a Window

CTRL + W + – Increase the current window by one line. You can also increase n rows by n. CTRL + W – — Decreases the current window by one line. You can also reduce n rows by n. CTRL + W_ – The current window expands as large as possible. You can also set the number of rows with n. :resize n — The height of the current window n lines. CTRL + W = — All Windows are the same height. N CTRL + W_ — The height of the current window is set to N lines. CTRL + W < — Reduce the current window by one column. You can also subtract n columns by n. CTRL + W > — Widen the current window by one column. You can also use n to widen n columns. CTRL + w | – the current window as wide as possible. You can also set the number of columns with n.

10.5 Switching between and Moving Windows

If the mouse is supported, it is easy to toggle and resize child Windows. CTRL + W CTRL + W: Switch to the next window. Or CTRL + W, W. CTRL +w p: Switch to the previous window. CTRL +w h(L,j,k): Switch to the left (right, down, up) window. CTRL +w t(b): Switch to the top (bottom) window. CTRL +w H(L,K,J): Move the current window to the left (right, top, bottom) side. CTRL + wr: Rotate the position of the window. CTRL + wt: Moves the current window to the new TAB.

11. Quick editing

11.1 Changing Case

~: Reverses the case of the character where the cursor is located. U or U in visual mode: Changes the selected text to uppercase or lowercase. Gu (U) a range (such as $, or G) that converts all letters from the current position of the cursor to lowercase or uppercase. Such as ggguG, is the beginning to the last line between all letters into small. In the case of GU5j, make the current line and the next four all lowercase.

11.2 Replacement (Normal Mode)

R: Replaces the character at the cursor, also supporting Chinese characters. R: To enter replacement mode, press ESC to return to normal mode.

11.3 Undo and Redo (Normal Mode)

[n] u: Cancel one (n) change. :undo 5 — Undo 5 changes. :undolist — Your undo history. CTRL + R: Redo the last change. U: Cancel all changes in the current line. : 4m — 4 minutes before: 55s — 55 seconds ahead

11.4 the macro

Qa: Start recording macro A (keyboard operation record) Q: Stop recording @a: Play macro A

12. Edit special files

12.1 File Encryption and decryption

Vim -x file: Starts editing an encrypted file. :X — Sets the password for the current file. :set key= — Remove the file password. Here are the more advanced VI skills summarized by Dian Hu.

12.2 File Coding

:e ++enc=utf8 filename, tell Vim to open the file with utF-8 encoding. :w ++enc= GBK, regardless of the current file encoding, save it to GBK encoding. :set fenc or :set fileEncoding to view the encoding of the current file. Add set FileEncoding = UCS-BOM, UTF-8, CP936 to vIMRC and VIM will select the appropriate encoding based on the file to open. Note: Do not leave Spaces between codes. Cp936 corresponds to the GBK code. Ucs-bom corresponds to the file format in Windows. Getting Vim to handle file formats and file encodings correctly depends on the correct configuration of ~/.vimrc

12.3 File Format

There are roughly three file formats: Unix, DOS, MAC. The difference between the three formats mainly lies in the encoding of the carriage return key: DOS is carriage return plus line feed, Unix only line feed, MAC only carriage return. :e ++ff= DOS filename, let Vim open the file in DOS format. :w ++ff= MAC filename to store the file in MAC format. :set ff, displays the current file format. Add set fileformats= Unix, DOS, MAC to vimrc to let vim automatically recognize fileformats.

13. Programming assistance

13.1 Some Keys

Gd: Jump to the definition of local variables; GD: Jump to the definition of the global variable and search from the beginning of the current file; g; : Last modified place; G,: next modified place; [[: to jump to the start of the previous function block, a single line of {.]]: to jump to the start of the next function block, a single line of {is required. []: Jumps to the end of the previous function block, requires a single line}. ] [: jumps to the end of the next function block, requiring a single line}. [{: jumps to the beginning of the current block;]}: jumps to the end of the current block; [/: jumps to the beginning of the current comment block;]/: jumps to the end of the current comment block; %: Not only can you move to a matching (),{}, or [], but you can also jump between #if, #else, and #endif. The parenthesis matching below is useful for programming.

Ci ‘, di’, yi’ : Modify, cut, or copy the contents between ‘. Ca ‘, da’, ya’ : Modify, cut, or copy the contents between ‘, including ‘. Ci “, di”, yi” : modify, cut, or copy “between the contents. Ca “, da”, ya” : Modify, cut, or copy the contents between “, including “. Ci (, di(, yi(: modifies, cuts, or copies the content between (). Ca (, da(, ya(: modifies, cuts, or copies content between (), including (). Ci [, di[, yi[: modifies, cuts, or copies the contents between []. Ca [, da[, ya[: modifies, cuts, or copies the contents between [], including []. Ci {, di{, yi{: modifies, cuts, or copies the contents between {}. Ca {, da{, ya{: Modify, cut or copy the contents between {}, including {} ci<, di<, yi< : modify, cut or copy the contents between <> Ca <, da<, ya< : modify, cut or copy the contents between <>, including <>.

13.2 ctags

ctags -R: -r also generates tags for files in subdirectories: Set tags= PATH /tags — tells Ctags which tag file to use :tag XYZ — jumps to the definition of XYZ, or places the cursor over XYZ by pressing C-], Return to c-T :stag XYZ — displays the definition of XYZ in a split window, or C-w], if c-w n], it opens a window n lines high :ptag XYZ — opens the definition of XYZ in the preview window with the hotkey C-w}. :pclose — Close the preview window. The hot bond is C minus W and z. :pedit abc.h — Edit abc.h in the preview window :psearch ABC — Search the files of the current file and include of the current file and display the lines containing ABC. Sometimes a tag can have multiple matches, such as function overloading, where a function name can have multiple matches. This will jump to the first match.

:[n] tNext — the next [n] match. :[n]tprev — the last [n] match. :tfirst — the first match :tlast — the last match :tselect TagName — Open the selection list TAB completion

:tag XYZ – Complete the tag names starting with xyz. Press TAB again to display other tags. :tag /xyz — will be completed with tag names that contain xyz in their names.

13.3 cscope

cscope -Rbq: Generate the cscope.out file :cs add /path/to/cscope.out /your/work/dir :cs find c func — Find where func is called: CW — Open the Quickfix window to see the result

13.4 gtags

Gtags combines the functions of Ctags and CScope. To use Gtags, you need to have GNU Gtags installed. Then run gtags in the project directory. :Gtags funcName locates the definition of funcName. :Gtags -r funcName Queries where funcname is referenced. :Gtags -s symbol Locates where symbol appears. :Gtags -g String Goto Where string appears. :Gtags -gi string ignores case. :Gtags -f filename Displays a list of functions in filename. You can display the current file using Gtags -f %. :Gtags -p pattern Displays files that contain a specific pattern in the path. For example :Gtags -p. H $displays all header files, :Gtags -p /vm/ displays files in the VM directory.

13.5 build

Vim provides :make to compile the program. The default call is make. If you have a makefile in your current directory, simply :make. If you don’t have a make program, you can change the program that make calls by configuring the MakePRg option. If you have only one abc.java file, you can set it to: set makeprg=javac\ abc.java and then :make. If there is a bug in the program, you can view the error through the Quickfix window. However, to locate the error correctly, you need to set errorFormat so that VIM recognizes the error message. Such as: setl efm = A % f, % % l: \ % m, % Z % p ^, % – C %. The % # % f filename, % l said line number, error % m said information, other can’t understand. Please refer to help ErrorFormat.

13.6 Quickly Modifying a Window

The quickFix plugin is useful for compiling debuggers šŸ™‚ :copen — opens a quick change window. :cclose — Closes the quick Change window. Quick change Windows are very useful when making programs, when: :cl — lists errors in the quick change window after make. :cn — Locate the next error. :cp — locates the last error. :cr — Locate the first error.

13.7 Automatic Completion

C-x C-S — Spelling suggestions. C-x C-v — Complete vim options and commands. C-x c-l — full line completion. C-x c-f — Automatic file completion path. When the menu pops up, press C-F to select, or C-n and C-p. C-x C-P and C-x c-N — complete the current word with words that have appeared in the document. You can also press C-P and C-n. C-x C-O — You can complete keywords and function names when programming. C-x c-i — complete according to the keywords in the header file. C-x C-d — Complete macro definition. C-x C-n – complete by the key that appeared in the buffer. Just press C-N or C-P. When the completion menu pops up: C-P switches members forward; C-n backward switching member; C-e Exits the drop-down menu and returns to the original input text; C-y Exits the drop-down menu and accepts the current option.

13.8 Indent multiple lines

In normal mode, press > twice. The line where the cursor is located is indented. If you press n first, then press > twice; , the n lines below the cursor are indented. Corresponding, press <; , the line where the cursor is is indented. If you are editing a code file, you can adjust it with =. In visual mode, select the block of code to adjust, press =, and the code will be indented according to the writing rules. Or n =, adjust the indentation of n lines of code.

13.9 fold

Zf — creates a collapsed command that can be used on a viewable area; Zd — Deletes the current row collapse; ZD — Deletes the current row collapse; Zfap — Collapses the segment where the cursor is; Zo — Opens folded text; Zc — fold up; Za — Open/close current fold; Zr — open nested folds; Zm — Fold up nested folds; ZR (zO) — Opens all folds; ZM (zC) — Fold all lines; Zj — Skip to the next fold; Zk — Jump to the previous fold; zi — enable/disable fold;

14. The command line

In normal mode, press: to enter the CLI mode

14.1 Shortcut Keys in CLI Mode:

Up and Down arrow keys: Up or next command. If some commands have been entered, the system searches for the previous or next matching command. Left and right arrow keys: Move left/right one character. C-w: Delete a word forward. C-h: deletes one character forward, equivalent to Backspace. C-u: moves from the current position to the beginning of the command line. C-b: Moves to the beginning of the command line. C-e: move to the end of the command line. Shift-left: Shift a word to the Left. Shift-right: Shift a word to the Right. @ : Repeat the previous colon command. Q: In normal mode, q then presses ‘:’ to open the command line history buffer and edit the command as if it were a file. Q/q? You can open it to find history.

14.2 Running External Commands

:! CMD executes external commands. :!!!!! Execute the last external command. :sh calls the shell and returns vim with exit. :r ! CMD inserts the result of the command at the current location of the file. :m,nw ! CMD takes the contents between lines M and N of the file as command input to execute the command.

15. Other

15.1 Working Directory

: PWD Displays the working directory of vim. : CD path Changes the working directory of vim. :set Autochdir enables Vim to automatically switch working directories based on the files you edit.

15.2 Some Shortcut Keys (Collecting)

K: Open manpage of the word where the cursor is located. : Looks down for the word where the cursor is. G: same as above, but partially match. #: Search up for the word where the cursor is. G# : same as above, but only partially. G C-G: indicates the number of words in the full text or part of the statistics.

15.3 Online Help

: H (ELP) or F1 open total help. :help user-manual Opens the user manual. Command help is in the following format: The first line specifies how to use the command; This is followed by an indented paragraph explaining what the command does, followed by further information. : Helptags somePath Generates indexes for documents in somePath. : Helpgrep searches the entire help document, and a list of matches is displayed in the Quickfix window. Ctrl+] jumps to the Tag theme, Ctrl+ T jumps back. :ver Displays the version information.

15.4 Some Minor Functions

Simple calculator: In insert mode, type C-r = and then enter the expression to get the result at the cursor