3

Executing One Line in VSCode–#SQLNewBlogger

 5 months ago
source link: https://voiceofthedba.com/2023/12/11/executing-one-line-in-vscode-sqlnewblogger/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

I wrote about arrays in PowerShell last week, but I realized one of the things I did while experimenting was look up how to run code a line at a time. I’m sure you can Google for that, but I decided to write a post to help me remember this in the future.

Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

Running One Line

Years ago I saw someone demonstrating either PoSh or Python in Visual Studio and they were walking through code a line at a time. I thought that was cool, like a debugger, but not being in the debugger.

To do this in VS Code, we use F8. Here’s how it works. Create a new PoSh file in VS Code. You should see something like this:

2023-12-01 14_01_11-● oneline.ps1 - Visual Studio Code_thumb[1]

Now put the cursor on line 1, anywhere. I’ll put it after the = sign. If I press F8, I see this:

2023-12-01 14_02_03-● oneline.ps1 - Visual Studio Code_thumb[1]

Pretty cool. I just ran that line.

One Hassle

The one hassle is the focus is now in the terminal. However CTRL+Tab gets me back to the editor, though it would go to the Welcome tab here. However, supposedly CTRL+1 or 2 would work.

My problem is those are mapped to ZoomIt, which is always running Sad smile

I hit CTRL+Tab twice, however, and I was back in my editor. I could go down one line and hit F8 to run the second code.

2023-12-01 14_02_52-● oneline.ps1 - Visual Studio Code_thumb[1]

Try it for yourself.

If you have a better method, let me know.

SQL New Blogger

After the last post, I spent less than 10 minutes setting up a new file and then capturing some code. A couple google searches helped me figure out the terminal/editor switching.

This was fun, but it also showcased some learning and something that will help me in my work. You could easily do the same thing, with any tool you use at work. Show how you experiment and learn.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK