Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to select code between certain characters

TL DR

Is there some extension, or other functionality, to select code above and below the cursor that is surrounded by some characters, e.g. %% or % ===== or anything else?

Why

I am coding Matlab in VSCode, since the builtin Matlab editor lacks a lot of useful functionalities. However, One thing that I miss is the ability to run 'sections':

%% section 1
x = 0:0.01:pi;
y = sin(y);
plot(x,y);

%% section 2
x = 0:0.01:pi;
y = cos(y);
plot(x,y);

%% section 3
x = 0:0.01:pi;
y = tan(y);
plot(x,y);

A section can be run using Ctrl+Enter. Since I use Matlab on Windows, there is no support for running the Matlab interpreter from the terminal/cmd.

So I created some AutoHotKey scripts that will copy selected code, open the Matlab window, paste it, and run. This works fine, however, when I want to run a very large section, this means that I have to select this manually, and press my defined shortcut to call the AutoHotkey script. Hence above question.

So say I have the cursor at some line insection 2, how can I select only the code in this section (including or excluding section 'headers', these are comments so does not matter).

like image 530
rinkert Avatar asked Jan 28 '26 19:01

rinkert


1 Answers

I have made an extension Select By that allows the selection based on regular expressions relative to the cursor position. You can specify different expressions for forward and backward search and if you want to include the searched text in the selection.

You can set up to 5 regex searches.

The extension defines 5 commands that can be used in keyboard shortcuts

like image 101
rioV8 Avatar answered Jan 31 '26 11:01

rioV8