Dividing Julia file in sections (VS code)

Hi everyone,

I was wondering if you can divide your Julia file in sections. I use this a lot when coding in Python so I don’t have to run every piece of code all the time. In Python VS code we can use #%% to divide in sections. But I couldn’t find the same operation for Julia. Is there something similar for Julia?

Thanks for helping me out.

1 Like

Yes, this is discussed in the docs here:

https://www.julia-vscode.org/docs/stable/userguide/runningcode/#Julia:-Execute-Code-Cell-(ShiftEnter)-1

You can delimit blocks with ## and execute them with the Julia: Excecute Code Cell command (which apparently is bound to Shift-Enter in standard keybindings, but I’ve changed mine so can’t check).

4 Likes

I’ve a problem using VS code that seems related to this. If I try to run code cells with Shift+Enter (as I used to), blocks of code are run instead than single lines. Has something changed with recent Julia or VS code updates? I never did divided files in sections

You can set your own keyboard shortcuts for VSCode commands under File → Preferences → Keyboard Shortcuts.

To run one line at a time, you probably want to set a shortcut for the VSCode command Julia: Send Current Line or Selection to REPL.

You can search through all available commands under View → Command Palette.