How to input multiple lines in Julia REPL

How to input multiple lines in Julia REPL in Windows System, I try to use Ctrl + Enter, but it doesn’t work.

For me, Esc + Enter works

3 Likes

Parentheses help:

julia> (1+2
       +3
       +4 + 5)
15

But to define a struct as in the example, you just need to ENTER after each line.

1 Like

On WIndows you can Shft+Alt+Enter , it’s the same as Esc+Enter, but I find it more smooth.

1 Like

Cool!

Very smooth thx. I think Julia vs code should add this shortcut in the official document.

Yes, thx!

I find in vs code, Alt + Enter also works.

Note that the result may not be the same as when using parentheses:

julia> 1+2
       +3
       +4 + 5
9

while the “correct” result is: 15

Maybe you know but to have addition (or other operations like multiplication) work across multiple lines, the operator needs to be at the end of each line:

julia> 1+2+
       +3+
       +4 + 5
15

(The reason for the result 9 in the other case is that this is the result of the last line.)

4 Likes

Using parentheses is simpler, as the plus can be anywhere.

Esc + Enter between each entry works in WSL2 Arch Linux listing each entry vertically.

Using semicolons between each entry is quick if you’re just looking for the solution and don’t need to see the entries listed vertically. For ex - in Julia REPL:

x = 10; y = 10; z = x + y; println(z);

Hit Enter for solution.

See