Vim's powerful operation

Source: Internet
Author: User

Using Vim can be useful for some powerful functions. This section describes its advanced features.

First, the abbreviation

Abbreviations for words
: IAB AD Advertisement
When you type AD, the advertisement is automatically complete
Abbreviations for statements
: IAB FFT for i from to do {

Second, macro operation

When programming, we usually use some repetitive actions. We can simplify our process with macro operations.
1, start with the QA command, where a can be any one letter, this operation indicates that the subsequent actions are recorded
2. Perform operation
3. End command with Q
Use @a to perform the operation just recorded, [email protected] is executed three times

Third, key mapping, definition

In addition to the predefined help functions for F1, the rest of the keys do not have predefined content in vim and can be used for key mapping.

  • Map commands in normal mode
  • IMAP commands in insert mode
  • Cancel the mapping of a key unmap command
    ****
    If there are parameters in the repeating operation, we can create a new command by: command.
    Example 1: We want to replace all output of the current line with Reg
    : Command SS s/output/reg/g
    Next execution : SS is equivalent to execution : s/output/reg/g
    Example 2: The meaning of the command : command-nargs=+ SS s/output/
    -nargs=1 of 1 parameters
    -nargs=* any number of parameters
    -nargs=? 0 or 1 parameters
    -nargs=+ 1 or more parameters
    : command-range=% SS
    -range default when moving forward
    -range=% All rows By default
    Redefine a command ": command! Ss
    Delete a command: Delcommand SS
    Be sure to note the position of-range and-nargs in the command.

    Block operation Block operations in the daily selection of a large segment, the operation of this large segment is very useful. Here are some examples of block operations.
    The CTRL + V command can enter a visual mode in which you can select a rectangle of text and then manipulate the text
    This operation can be divided into two parts: the first part is selected, the second part is the operation.
    The first step: place the cursor at the desired starting position, then press CTRL + V to enter the visual module, and combine the JKHL key to select the rectangular block you want. The rectangular block is highlighted in this state.
    Step Two:
  • I, add the text cursor to the left of the text block on the first line, after you type the text, and end with the ESC key, you can manipulate the entire block.
  • A, add text to the right of the text block
  • C, delete the text block and add the text
  • R, the entire block of text is replaced with a character typed after R
  • The entire text block is shifted right by one tab distance
  • < The entire text block moves left one tab distance
  • Y,copy a block of text
  • P, paste
  • d/x, deleting
    Note: for block {} These three kinds of parentheses, you can place the cursor on {[(above) and type the command, which mainly includes:
    >%, indent the distance of a tab
    d%, delete the entire statement block
    Y%,copy the entire block statement

    Five, multi-file editing 1, VIM support to open multiple files in the same vim : E aa.v, if the file is not in the current directory, then you need to specify a relative or absolute path.
    The current file that is closed at this time does not disappear but is placed in a buffer of vim. by : LS or: buffers can produce a list of buffers. The following command can go to the file you want to jump to.
  • : Buffer2, where 2 is the buffer number, by: Ls/:buffers view
  • : B2
  • : Buffers AAA.V, use Tab key to complete auto-completion function

2. Multi-window editing
    • : Split aaa.v:sp aaa.v, sub-screen display of AAA.V files up and down
    • : Vsplit Aaa.v:vs aaa.v, left and right split screen display
    • : E ex1-1, open the Ex1-1 file to replace the current cursor location file.
    • :Close, closes the current window
    • :only, close all other windows to keep the current window only
    • : Split aaa.v, top and bottom split screen display
    • :New, opens a window
    • : Qall : Wall : Wqall : Exit all, save all, exit and save All
      At the bottom of the Linux command line, you can open several files by typing the command screen directly.
    • Vim-o file1 file2: Vertical split screen Open file
    • vim-o file1 file2: Open file on horizontal split screen GF, shortcut keys, you can position the cursor on the file name, you can open the files directly
      : BR, command back to file list
      Example: IMPORT/HOME/X00464410/XUQING.V Note If it is not under this path, be sure to indicate the relative path or absolute path.
      This command has a very simple application when looking at the top-level file in the Vim editor.

Vim's powerful operation

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.