skip to Main Content

I would like to select all the words at once between the backtick. In MACOSX use alt+ shift and the cursor put a multi cursor at the beginning of the words but I can’t stop the selection to the "`" character where the word ends.

  `apples` int(200) NOT NULL,
  `bananas` int(100) NOT NULL,
  `mangos` int(100) NOT NULL,
  `kiwi` int(100) NOT NULL,
  `raspberry` int(100) NOT NULL,

Is there a way I can select until some character is found in the line where the cursor is placed?
In this case, the expected selection is:

  `apples` 
  `bananas`
  `mangos`
  `kiwi`
  `raspberry`

4

Answers


  1. If there is a dedicate way to select until a specific character, I am not aware of it.

    However, you have a very regular "input" here (none of the fruit words have spaces in them). If that’s representative of your real scenario, then to select apples, bananas, mangos, kiwi, raspberry, then put the caret right at the beginning of "`apple`", then hold alt+shift and click the beginning of "raspberry", then press ctrl+shift+right, then shift+right (Windows and Ubuntu. I think for MacOS it’s option+shift+right then shift+right, but I’m not 100% sure).

    This doesn’t work if the fruit words have spaces in them. In that case, if you happen to be doing this because you want to do find and replace, you can use the regular expression mode of the find and replace feature. Something like find ^ `([^`]+)` and then replace withsome usage of $1.

    Login or Signup to reply.
    • Press command+F to open the find widget.

    • Type `.*?` in regex mode (.* icon).

    • Press command+shift+L to select all occurrences.

    • Press esc to close the find widget.

    Login or Signup to reply.
  2. You can use the extension Select By

    Create a keybinding:

      {
        "key": "shift+alt+]",  // or any other combo
        "command": "selectby.regex",
        "when": "editorTextFocus",
        "args": {
          "forward": "('''|"""|'|"|`)",
          "forwardNext": "{{1}}",
          "forwardInclude": false,
          "forwardNextInclude": false
        }
      }
    

    Place multiple cursors before the strings you want to select, and press the key binding.

    Login or Signup to reply.
  3. If you do this selection frequently you can make a keybinding for it using this extension: Find and Transform (which I wrote). Sample keybinding – in your keybindings.json:

    {
      "key": "alt+d",                 // whatever keybinding you want
      "command": "findInCurrentFile",
      "args": {
        "find": "(?<=`)(.*)(?=`)",
        "restrictFind": "selections",
        "isRegex": true
      },
    }
    

    For this you just need to select the lines you want changed – it can be one selection, see demo. Or you could use this option:

    "restrictFind": "line",
    

    and just put a cursor on any lines you want changed – the cursor can go anywhere on the line.

    select in backticksticks demo

    By "line":

    select in backticks by line demo

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