# PSA: Inserting a new line in the REPL

**URL:** https://discourse.julialang.org/t/psa-inserting-a-new-line-in-the-repl/3524
**Category:** General Usage
**Created:** [May 4, 2017, 11:43pm UTC](https://discourse.julialang.org/t/psa-inserting-a-new-line-in-the-repl/3524 "2017-05-04T23:43:14Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![joshbode](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshbode/32/260_2.png) [@joshbode](https://discourse.julialang.org/u/joshbode)
#### Post date: [May 4, 2017, 11:43pm UTC](https://discourse.julialang.org/t/psa-inserting-a-new-line-in-the-repl/3524/1 "2017-05-04T23:43:14Z")

</div>

This tip may help someone - I’ve found it useful myself 🙂

Ever wanted to insert a new blank line into something you’re working on at the REPL?  
Just pressing `<Enter>` is going to execute the command!

TL;DR Use: `<Esc>` followed by `<Enter>` (or `<Alt><Enter>` works too, which may be easier to type)

Note: this trick works mid-line to break a long line, too!

(on macOS to get `<Alt><Enter>` working it may require an option to be set in your terminal application - look for options about the “Meta-key”)

For example, suppose you’ve just typed/pasted the following definition for the function `f`:

```julia
julia> function f(x, y)
           x + y
       end

```

But you’d like to insert another line above `x + y`.

Press the `<Up>` key to get back what you previously typed, and move the cursor to the start of that line (or the end of the preceding line (denoted by `█`):

```julia
julia> function f(x, y)
       █ x + y
       end

```

then press the `<Esc>` key followed by `<Enter>`, giving you:

```julia
julia> function f(x, y)
       █
           x + y
       end

```

at which point you can make your edit:

```julia
julia> function f(x, y)
           y = y >= 0 ? sqrt(y) : 0
           x + y
       end

```

---

<div class="post-metadata">

### Author: ![joshbode](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshbode/32/260_2.png) [@joshbode](https://discourse.julialang.org/u/joshbode)
#### Post date: [May 4, 2017, 11:56pm UTC](https://discourse.julialang.org/t/psa-inserting-a-new-line-in-the-repl/3524/2 "2017-05-04T23:56:57Z")

</div>

Other useful readline keys:

- `<Ctrl><k>`: kill (cut) to the end of the line
- `<Ctrl><y>`: yank (paste) what was last killed (cut)
- `<Ctrl><w>`: kill (cut) the preceding word
- `<Ctrl><r> substring`: recursively search through your history for `substring`.  
Keep hitting - `<Ctrl><r>` until you get the right one if there are multiple matches.

See the docs on Julia’s REPL [key bindings](https://docs.julialang.org/en/latest/manual/interacting-with-julia.html#Key-bindings-1) for more gems.

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [May 5, 2017, 12:17am UTC](https://discourse.julialang.org/t/psa-inserting-a-new-line-in-the-repl/3524/3 "2017-05-05T00:17:57Z")

</div>

`Alt-Enter` is usually easier to reach.

---

<div class="post-metadata">

### Author: ![joshbode](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshbode/32/260_2.png) [@joshbode](https://discourse.julialang.org/u/joshbode)
#### Post date: [May 5, 2017, 12:41am UTC](https://discourse.julialang.org/t/psa-inserting-a-new-line-in-the-repl/3524/4 "2017-05-05T00:41:32Z")

</div>

Good point - I’m on a Mac, but I’ve never been able to get `<Alt><Enter>` to work, though I have mapped `<CapsLock>` as `<Esc>` 🙂

---

<div class="post-metadata">

### Author: ![andyferris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andyferris/32/235_2.png) [@andyferris](https://discourse.julialang.org/u/andyferris)
#### Post date: [May 5, 2017, 10:30am UTC](https://discourse.julialang.org/t/psa-inserting-a-new-line-in-the-repl/3524/5 "2017-05-05T10:30:24Z")

</div>

I note that shift-enter is almost universal in the internet age/web related apps for this purpose… plus I thought the goal was to be a bit more modern than readline?

---

<div class="post-metadata">

### Author: ![shorty66](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shorty66/32/3254_2.png) [@shorty66](https://discourse.julialang.org/u/shorty66)
#### Post date: [May 5, 2017, 12:37pm UTC](https://discourse.julialang.org/t/psa-inserting-a-new-line-in-the-repl/3524/6 "2017-05-05T12:37:53Z")

</div>

`Alt-Enter` does not work on windows as it is used to toggle fullscreen.

I second the proposal for `Shift-Enter` or `Ctrl-Enter` (Notebook-Style).

---

<div class="post-metadata">

### Author: ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)
#### Post date: [May 5, 2017, 6:26pm UTC](https://discourse.julialang.org/t/psa-inserting-a-new-line-in-the-repl/3524/7 "2017-05-05T18:26:03Z")

</div>

> [@shorty66](#):
>
> Alt-Enter does not work on windows as it is used to toggle fullscreen.

See [Pick a different key binding for "Insert new line without executing it" at least on Win · Issue #18295 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/18295).

I never managed to do the keyboard customization suggested in that issue. Would be great if someone took a crack at that, it makes the REPL quite difficult to use on Windows…

---

<div class="post-metadata">

### Author: ![Anderssorby](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anderssorby/32/11748_2.png) [@Anderssorby](https://discourse.julialang.org/u/Anderssorby)
#### Post date: [December 5, 2019, 1:27pm UTC](https://discourse.julialang.org/t/psa-inserting-a-new-line-in-the-repl/3524/8 "2019-12-05T13:27:28Z")

</div>

I’m used to that yank means copy (from vim) are you sure that y stands for yank?

---

<div class="post-metadata">

### Author: ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)
#### Post date: [December 5, 2019, 2:00pm UTC](https://discourse.julialang.org/t/psa-inserting-a-new-line-in-the-repl/3524/9 "2019-12-05T14:00:03Z")

</div>

[https://docs.julialang.org/en/v1/stdlib/REPL/#Key-bindings-1](https://docs.julialang.org/en/v1/stdlib/REPL/#Key-bindings-1)

(then search for yank for explanations)

EDIT: Oh, and I should have said welcome!

---

<div class="post-metadata">

### Author: ![Anderssorby](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anderssorby/32/11748_2.png) [@Anderssorby](https://discourse.julialang.org/u/Anderssorby)
#### Post date: [December 8, 2019, 2:05pm UTC](https://discourse.julialang.org/t/psa-inserting-a-new-line-in-the-repl/3524/10 "2019-12-08T14:05:38Z")

</div>

I see the documentation says so, but the use of the word is opposite of what it means i vim/vi. I think other people will find this confusing as well. In the dictionary it is defined as: pull with a jerk. Sounds more like copying to me.

Maybe it should be changed to p for paste for example.

---

<div class="post-metadata">

### Author: ![joshbode](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshbode/32/260_2.png) [@joshbode](https://discourse.julialang.org/u/joshbode)
#### Post date: [December 8, 2019, 11:07pm UTC](https://discourse.julialang.org/t/psa-inserting-a-new-line-in-the-repl/3524/11 "2019-12-08T23:07:36Z")

</div>

“Yank” and the key-binding is consistent with the terminology used in Emacs and Readline for the same action:

[https://www.gnu.org/software/emacs/manual/html\_node/emacs/Yanking.html](https://www.gnu.org/software/emacs/manual/html_node/emacs/Yanking.html)

> **[Readline Killing Commands (Bash Reference Manual)](https://www.gnu.org/software/bash/manual/html_node/Readline-Killing-Commands.html)**
>
> Readline Killing Commands (Bash Reference Manual)

That said, I’m a Vim user and it would be great to see vi keybindings in the Julia REPL (where `y` is a copy-action) 🙂

---

<div class="post-metadata">

### Author: ![tamasgal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamasgal/32/27946_2.png) [@tamasgal](https://discourse.julialang.org/u/tamasgal)
#### Post date: [December 8, 2019, 11:34pm UTC](https://discourse.julialang.org/t/psa-inserting-a-new-line-in-the-repl/3524/12 "2019-12-08T23:34:16Z")

</div>

Indeed, vim modes would be awesome.

---

<div class="post-metadata">

### Author: ![lwhitefox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lwhitefox/32/4363_2.png) [@lwhitefox](https://discourse.julialang.org/u/lwhitefox)
#### Post date: [December 9, 2019, 12:32am UTC](https://discourse.julialang.org/t/psa-inserting-a-new-line-in-the-repl/3524/13 "2019-12-09T00:32:18Z")

</div>

Decades long Emacs guy: Ctrl-y rules 😀

---

<div class="post-metadata">

### Author: ![lungben](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lungben/32/12314_2.png) [@lungben](https://discourse.julialang.org/u/lungben)
#### Post date: [February 4, 2022, 3:29pm UTC](https://discourse.julialang.org/t/psa-inserting-a-new-line-in-the-repl/3524/14 "2022-02-04T15:29:59Z")

</div>

> [@shorty66](#):
>
> `Alt-Enter` does not work on windows as it is used to toggle fullscreen.

Just in case anyone stumbles across this old thread again (like I did):  
Alt+Shift+Enter for a new line in Julia REPL works under Windows

---

<div class="post-metadata">

### Author: ![jcbritobr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcbritobr/32/219275_2.png) [@jcbritobr](https://discourse.julialang.org/u/jcbritobr)
#### Post date: [March 31, 2022, 6:02pm UTC](https://discourse.julialang.org/t/psa-inserting-a-new-line-in-the-repl/3524/15 "2022-03-31T18:02:30Z")

</div>

Yep, It works, but move line and ident line commands alt + arraows did not workd

---

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [August 4, 2023, 2:35pm UTC](https://discourse.julialang.org/t/psa-inserting-a-new-line-in-the-repl/3524/16 "2023-08-04T14:35:45Z")

</div>

On macOS (with the default Apple Terminal), here is the relevant setting you need to toggle so that `Option + Enter` adds a newline:

 ![Screenshot 2023-08-04 at 16.32.23](https://global.discourse-cdn.com/julialang/original/3X/f/7/f7276b7833f7414072f82d536ae691d60bd94792.png)
