skip to Main Content

Question

I know multiple cursor is a thing in VSCode, but is there a single action (keyboard shortcut or a command) to place a new cursor every N lines in the whole file, based on initial cursor location?

Or as an alternative good-enough solution, is there a way to generate X new cursors N lines after the current one?

Context

The use case behind this question is as follow:

Imagine you have a very large json file with repeating blocks in it, the content of each blocks has the same number of lines but a very high text variability on each line.

I would like to be able to multi select all blocks using the way above, and batch-copy them to another file with a similar structure this way.

Example

{
  "main_block": {
    "name": "TEST NAME",
    "version": "1.0"
    "data_list": [
      {
        "label": "Item Name 1",
        "obj_id": "ID1111111",
        "obj_type": "TypeA",
        "properties": [
          {
            "name": "param1",
            "size": 0,
            "value": "test_value1"
          },
          {
            "name": "param2",
            "size": 10,
            "value": "test_value2"
          }
        ]
      },
      ...
      {
        "label": "Item Name 9",
        "obj_id": "ID9999999",
        "obj_type": "TypeB",
        "properties": [
          {
            "name": "param42",
            "size": 42,
            "value": "test_value42"
          },
          {
            "name": "param57",
            "size": 0,
            "value": "test_value57"
          }
        ]
      }
    ]
  }
}

Reformulating context with the example above:

  • The number of lines of each object inside data_list is guaranteed to be the same (17 lines).
  • In order to be able to select the first object inside each properties array through the whole file, I am looking for a way to place a cursor every 17th lines.

2

Answers


  1. Chosen as BEST ANSWER

    I managed to cover the use case described above in a different way that does not involve specifying the number of line.

    As this is not answering the initial question please feel free to share more relevant solutions.

    For reference in case it fits your needs, here is what I did:

    • Find a text that appears exactly once before or after the block you want to select.
    • Select this text.
    • Press Ctrl+Shift+L to select all occurenced of this text in the file and put a cursor at the end of each.
    • Use Arrow keys to move all cursors at the beginning of the target block.
    • Use Shift+DownArrow to select the whole block and do whatever you need with it.

  2. you can use the extension I made: [Select By] and use the command:
    Place cursor based on line number, uses boolean expression

    For your use case the expression would be: c+17k

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search