With Vim for some time, I would like to write down some interesting tricks.
- Jump
- HJKL, left bottom right.
- B/E jump to top/next word
- ^/$ jump to wardrobe/tail
- from {, [, (, corresponding},],) jump to each other, you can use %
- Jump to the definition of a local variable GD, jump to the definition of a global variable GD
- Jump to the last modified place G; Note the g+ semicolon.
- Jump to the next modified place G, note is g+ comma
- : N, jump to n rows
- Matching symbols (', ', ', (), {}, [], <>) operations
- Ci?,di?,yi?,? for the above matching symbols, you can modify, cut, copy. The contents of which are not included?
- Ca?,da?,ya?,? for the above matching symbols, you can modify, cut, copy. Which of the contents, including?
- For example, deleting () does not include parentheses, only di?
- Copy a string "ABCDE", just need to move the cursor to it, ya "
- Indent code
- Auto indent =, if indent from beginning to end is Gg=g
- Specifies the area indent >,<, which can be combined with the visual mode, c-v into the bulk operation indent.
- Collapse function
- Move to {, zf%.
- Folding can also be ZFN so that you can collapse n rows
- Open folding, Zo
- Useful replacements
- The most basic substitution: a,bs/x/y/g, from line A to line B, replace X with Y, and no G replaces only the first of each line.
- Global Replacement:%s/x/y/g
- Delete only another empty line with an overhead: g/^\s*$/d
- Remove space at end of line:%s= *$==
- Bulk annotations
- Ctrl-v Enter visual mode, then I (Shift i), insert the comment, and then press ESC (Basic)
- From A to B, the leftmost comment: a,bs/^/#/(Python,php,shell, and so on), but the comments are all on the far left.
- The first non-empty word match either from A to line B inserts a comment:
- %s/([^]+)/#\1/
- :%s/[[:graph:]]\@=/#
- Search
- Search/pattern from cursor forward
- Search from cursor down? pattern
- Search only the beginning,/^pattern, or end of line/pattern$
- Search cursor forward with the word #
- From the cursor backwards soso the word with the cursor *
- In addition, the search, jumps to the previous n, the next n.
- Off highlighting yes: Noh
- Useful multi-label
- Open multi-label Tabe file name
- Move to the next tab,gt or: TABN
- Move to the previous TAB,GT or: TABP
- Move to nth label, n GT, note N GT to be separated by a space
- Close the label TABC, with the exit can also
- The other window is also very useful in the boot time Vim-o2 file1 file2, note is the letter O, not the number
- Interesting calculators
- In insert mode, press CTRL r =, enter the expression, and it will appear on the cursor.
- Recommend some interesting websites
- Good site for configuring plugins: http://vimawesome.com/
- A good site for getting started and practicing: http://www.openvim.com/
- More to add
Skill of Vim