Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search backward in visual studio code from current position

Suppose I have a very loooong file with all my libraries and its functions (can't change it, that's what I have to work with), all in one file, e.g.:

    [library1
    function 1
    blablablah1
    
    
    [library2
...
    function 2
    blablablah2

I want to find the closest [library...] line, to guess which library contains my current cursor line:

For example, if I have the cursor in the line "blablablah2", and do a search (ctrl+f), and start typing "[lib", the cursor immediately goes to "[library1" because it always start searching from the beginning of the file. I want that, when I start typing, the cursor don't start moving until I press the "up" arrow to search backwards... so I find the [library2] line.

like image 673
Roger Avatar asked Aug 13 '26 18:08

Roger


2 Answers

You can use the extension Select By.

Add this to your keybindings.json:

{
    "key": "ctrl+shift+f6",  // or any other key combo
    "when": "editorTextFocus",
    "command": "moveby.regex",
    "args": {
      "ask": true,
      "properties": ["prev", "start"]
    }
  }

You enter a regular expression (escape a few characters if needed).

like image 132
rioV8 Avatar answered Aug 17 '26 11:08

rioV8


Disable this setting:

Editor > Find: Cursor Move On Type

// Controls whether the cursor should jump to find matches while typing. "editor.find.cursorMoveOnType": false,

Now the cursor will not jump to matches as you type.

like image 40
Mark Avatar answered Aug 17 '26 09:08

Mark



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!