Home  >  Q&A  >  body text

How to interpret the di" command under vim?

When vim is editing, it is often necessary to delete things in quotation marks. I found this on the Internet. Similar ones are
di(, ci', etc., how do you understand the i here?

高洛峰高洛峰2711 days ago898

reply all(3)I'll reply

  • 阿神

    阿神2017-05-16 16:45:05

    i means inside, please refer to vim :help object-select

    For example, there is such a string
    "testdfat"

    Assume the cursor stays at the first t position

    • di":delete all content inside ",结果字符串为""
    • dta:delete all content to a,结果字符串为"at"
    • dfa:delete all content from current location, until a is found,结果字符串为"t"

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-16 16:45:05

    d means delete, and i almost means in. When combined, it means to delete the characters between the two quotation marks.

    The corresponding one is di' di( di< di{ .....

    d can also be replaced by c.

    There is also a similar daw das dap: delete a word/sentence/paragraph.

    reply
    0
  • 为情所困

    为情所困2017-05-16 16:45:05

    To understand this command you need to understand some basic concepts of VIM:
    1. operator: VIM provides many commands (operators) for modifying or editing text. These operators themselves are just a behavior, such as d is delete, c is change, But these operators need to know the object they are working on, so we need a method to provide it with a text object. You can think of these operators as a function that receives a text object for processing. For help documentation, please see help: operator
    2. text-objects: According to the name, it is a text object. This is the parameter to be passed to the operator. VIM provides some methods to select some text as text-objects, including the special commands a and i (don’t a and i enter insert mode? This will be explained later), where i means "inner" , such as 'hello, w^orld', (^ represents the cursor position), then i' will select hello, world, and a' within the single quotes, and a' will select the entire content including the single quotes. For more instructions, please see the documentation help: text-objects.
    3. Motion: Indicates movement. This is also the first thing you come into contact with when learning VIM, h, j, k, l, etc. In fact, each moving command will cover a text area, and this text area can also be used as a text-objects. For example, if 5w moves 5 words, these 5 words can actually be passed to the operator as a text-objects at this time. For example: d5w will delete 5 words. For more instructions, please see the documentation help: motion.
    4. Operator-pending mode: We all know that VIM has many modes. The first ones to understand are normal mode, insert mode, and command mode. From the name, this mode means that there is an operator in the pending state. The reason why there is this state is because you used the operator mentioned in 1. This operator requires a text object as a parameter, and it is waiting for you to give it a Such an object can be realized through the instructions in 2 or 3. This is why a and i will not enter insert mode at this time, because VIM is not in normal mode at this time, but in another mode. You can set set showcmd to let VIM display the current command. If it is operator-pending mode, you will see this command displayed in the VIM status bar. After passing the parameters required by the operator to it, VIM will return to normal mode after executing the command.

    It’s easy to understand di’ at this point:
    - d: VIM accepts the delete command and enters operator-pending mode
    - i': Using the current cursor position as the coordinate, select the text in the single quotes and pass it to d as the object to be deleted

    reply
    0
  • Cancelreply