search

Home  >  Q&A  >  body text

Please ask two questions to improve the efficiency of using vim.

1. How to search for multiple keywords at the same time
For example, I want to highlight all aa, bbbb, ccccc

in the document

2.Example
There is an enum

enum Test {
    TEST_A,
    TEST_BBBBB,
    TEST_CC,
    TEST_DDDDDDD,
    TEST_EEE
};

How to quickly add the following comments

enum Test {
    TEST_A,         // 0
    TEST_BBBBB,     // 1
    TEST_CC,        // 2
    TEST_DDDDDDD,   // 3
    TEST_EEE        // 4
};

For question 2, based on your answers and my own modifications, the method I use is as follows:

  1. set ve=all Allows the cursor to reach places without characters
  2. C-v Enter column block visual mode and select the column where you want to insert comments
  3. Press A and insert // 0, press Esc to return to normal mode
  4. VEnter line visual mode and select all lines with added comments
  5. Execute commandlet i=0|'<,'>g/0$/s//\=i/|let i=i+1
  6. set ve= Restore virtual editing options
给我你的怀抱给我你的怀抱2775 days ago795

reply all(3)I'll reply

  • 大家讲道理

    大家讲道理2017-05-16 16:43:13

    Second question:

    1. set ve=all Allows the cursor to reach places without characters
    2. C-v Enter column block visual mode and select the column where you want to insert comments
    3. Press A 并插入 // 0,按 Esc to return to normal mode
    4. Enter column block visual mode again and select that column 0
    5. Use the visIncr.vim command :I to change it to an increasing numerical sequence
    6. set ve= 把虚拟编辑选项复原(我推荐使用非默认值 block, so you don’t have to switch frequently)

    PS: Usually it cannot be represented by an enumerated integer, right?

    reply
    0
  • 阿神

    阿神2017-05-16 16:43:13

    The first question, use regular expressions when searching:

    Second question, just record a macro:

    1. First manually enter the gaze of the first line, that is, add a // 1 at the end
    2. Anywhere in the first line, record this macro: qq^f y$j$p^A
    3. Use it~

    Explain:

    • qq: 录制宏到寄存器 q
    • ^: Go to the beginning of the trip
    • f: (注意 f followed by a space), go to the first space
    • y$: Copy to end of line
    • j$p: Paste at the end of the next line
    • ^A: (This is Ctrl-A) +1

    reply
    0
  • 某草草

    某草草2017-05-16 16:43:13

    Second question

    Use 列编辑 to make a series of comments

    To auto-increment the number, in command line mode, enter the following command:

    :let i=0|g/0/s//\=i/|let i=i+1
    

    The source of the self-increasing solution is this article: link

    reply
    0
  • Cancelreply