Skill of Vim

Source: Internet
Author: User




With Vim for some time, I would like to write down some interesting tricks.


  1. 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
  2. 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 "
  3. 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.
  4. Collapse function
    • Move to {, zf%.
    • Folding can also be ZFN so that you can collapse n rows
    • Open folding, Zo
  5. 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= *$==
  6. 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:]]\@=/#
  7. 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
  8. 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
  9. Interesting calculators
    • In insert mode, press CTRL r =, enter the expression, and it will appear on the cursor.
  10. 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

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.