How to replace text between quotes in vi

后端 未结 6 2019
无人共我
无人共我 2020-12-07 12:12

Say I have this line of code:

$query = \"SELECT * FROM table\";

Is there a command in vi/vim which can instantly delete everything between

6条回答
  •  清歌不尽
    2020-12-07 12:42

    I've made a plugin vim-textobj-quotes: https://github.com/beloglazov/vim-textobj-quotes

    It provides text objects for the closest pairs of quotes of any type and supports quotes spanning multiple lines. Using only iq or aq it allows you to operate on the content of single ('), double ("), or back (`) quotes that currently surround the cursor, are in front of the cursor, or behind (in that order of preference). In other words, it jumps forward or backwards when needed to reach the quotes.

    It's easier to understand by looking at examples (the cursor is shown with |):

    1. Before: foo '1, |2, 3' bar; after pressing diq: foo '|' bar
    2. Before: foo| '1, 2, 3' bar; after pressing diq: foo '|' bar
    3. Before: foo '1, 2, 3' |bar; after pressing diq: foo '|' bar
    4. Before: foo '1, |2, 3' bar; after pressing daq: foo | bar
    5. Before: foo| '1, 2, 3' bar; after pressing daq: foo | bar
    6. Before: foo '1, 2, 3' |bar; after pressing daq: foo | bar

    The examples above are given for single quotes, the plugin works exactly the same way for double (") and back (`) quotes.

    You can also use any other operators: ciq, diq, yiq, viq, etc.

    Please have a look at the github page linked above for more details.

提交回复
热议问题