skip to Main Content

when I select a certain word in vscode and press ctrl+shift+l all occurrences of that word will be selected throughout the entire file, is there a way to achieve the same thing but only select the occurrences on the currently selected line?

3

Answers


  1. You can select using CTRL+SHIFT+L in the same way. First, you select the entire line with CTRL+L and then press CTRL+SHIFT+L to select all occurrences identical to the selected line. But attention to one detail, CTRL+L also selects any blank spaces on that line.

    Login or Signup to reply.
    • Select the word you want
    • Copy the word: Ctrl+C
    • Select the whole line: Ctrl+L
    • Start Find dialog: Ctrl+F
    • Select button: Find in Selection Alt+L
    • Paste Word: Ctrl+V
    • Select All in Selection: Alt+Enter

    If you find all the commands for these shortcuts you can combine them with multi-command extension into one key binding

    Login or Signup to reply.
  2. This is very easy with an extension I wrote, Find and Transform. Create a keybinding like:

      {
        "key": "alt+q",           // whatever keybinding you want
        "command": "findInCurrentFile",
        "args": {
          "description": "Select all matches on current line",  // whatever description you want
          "restrictFind": "line"
        }
      }
    

    Then just put the cursor into the word and trigger your keybinding.

    And if you want to replace those matches with something just put

    select all matches in line

    There are other options than within the current line, like the whole document, just the next or previous match, just the next match on the line, etc.

    And if you want to replace those matches with some text just put an additional arg into the keybinding:

    "replace": "my replacement text",
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search