# Confirm \`Ctrl-D\` to exit with \`y/n\` prompt like iPython?

**URL:** <https://discourse.julialang.org/t/confirm-ctrl-d-to-exit-with-y-n-prompt-like-ipython/105487>\
**Category:** General Usage\
**Tags:** question, repl\
**Created:** [October 27, 2023, 4:52pm UTC](https://discourse.julialang.org/t/confirm-ctrl-d-to-exit-with-y-n-prompt-like-ipython/105487 "2023-10-27T16:52:54Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![bert](https://avatars.discourse-cdn.com/v4/letter/b/9e8a1a/32.png) [@bert](https://discourse.julialang.org/u/bert)\
**Post date:** [October 27, 2023, 4:52pm UTC](https://discourse.julialang.org/t/confirm-ctrl-d-to-exit-with-y-n-prompt-like-ipython/105487/1 "2023-10-27T16:52:54Z")

</div>

When using the REPL, is there a way to have an ipython-style confirmation when pressing `Ctrl-D` to exit? Currently Julia does this:

```julia
julia> Type ^D again to exit.

julia> 

```

I’m not a fan of this because I think it’ll just train me to double-tap `Ctrl-D`, which can be destructive if using a Julia shell that’s not using my `startup.jl` (since it’ll exit the shell).

I’d much prefer ipython’s style:

```julia
In [1]:                                                                                                 
Do you really want to exit ([y]/n)? 

```

It is possible to get this in Julia?

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [October 27, 2023, 10:56pm UTC](https://discourse.julialang.org/t/confirm-ctrl-d-to-exit-with-y-n-prompt-like-ipython/105487/2 "2023-10-27T22:56:51Z")

</div>

It is very hard to type “CTRL-D” by accident.

You have to hold down the control key and hold down the D key at the same time. Do you regularly press ctrl-D by accident regularly?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 28, 2023, 12:00am UTC](https://discourse.julialang.org/t/confirm-ctrl-d-to-exit-with-y-n-prompt-like-ipython/105487/3 "2023-10-28T00:00:33Z")

</div>

> [@bert](#):
>
> It is possible to get this in Julia?

It’s certainly conceivable — it’s purely a REPL user-interface feature, so it wouldn’t be breaking. You could submit a [PR to modify this code](https://github.com/JuliaLang/julia/blob/93dbe3631999bc252cfc07f9c4d3b997f9168ce5/stdlib/REPL/src/LineEdit.jl#L2418-L2427) to implement it.

I’m not sure whether it would be accepted — I don’t have strong feelings either way myself — but it’s certainly a reasonable proposal.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [October 28, 2023, 1:05am UTC](https://discourse.julialang.org/t/confirm-ctrl-d-to-exit-with-y-n-prompt-like-ipython/105487/4 "2023-10-28T01:05:17Z")

</div>

Umm, that code seems to have already implemented the feature. There appears to be an option to turn it on somewhere.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 28, 2023, 2:31am UTC](https://discourse.julialang.org/t/confirm-ctrl-d-to-exit-with-y-n-prompt-like-ipython/105487/5 "2023-10-28T02:31:55Z")

</div>

> [@mkitti](#):
>
> Umm, that code seems to have already implemented the feature

I don’t follow you — that’s the code that prints `Type ^D again to exit.` I’m not seeing an option for `Exit? ([y]/n)` or similar?

What you can do already is to turn off (or on) the “ctrl-D twice” confirmation feature, so that typing `^D` only once causes you to exit, via:

```julia
atreplinit() do repl
    repl.options.confirm_exit = false
end

```

in your `~/.julia/config/startup.jl` file.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [October 28, 2023, 2:40am UTC](https://discourse.julialang.org/t/confirm-ctrl-d-to-exit-with-y-n-prompt-like-ipython/105487/6 "2023-10-28T02:40:45Z")

</div>

Ah, I misread the thread.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 28, 2023, 9:23am UTC](https://discourse.julialang.org/t/confirm-ctrl-d-to-exit-with-y-n-prompt-like-ipython/105487/7 "2023-10-28T09:23:20Z")

</div>

> <https://github.com/JuliaLang/julia/pull/24816#issuecomment-348821880>
>
> | REPL | Closes with one ^D |
> | :----: | :------: |
> | APL (Dyalog) | Yes |
> | …APL (ngn) | Yes |
> | IPython | \*\*No\*\* |
> | Julia | \*\*No\*\* |
> | Lisp (Clojure) | Yes |
> | Lisp (FemtoLisp) | Yes |
> | Lisp (SBCL) | Yes |
> | Octave | Yes |
> | Python 2 | Yes |
> | Python 3 | Yes |
> | R | Yes |
> | Ruby (IRB) | Yes |
> | Ruby (Pry) | Yes |
> | Rust (rusti) | Yes |
> | Scheme (icyc) | Yes |
> 
> Note in particular the disconnect between the Python REPL and IPython. It seems like if we want to provide something like this, it could be through IJulia or whatever rather than the stock Julia REPL.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 28, 2023, 9:25am UTC](https://discourse.julialang.org/t/confirm-ctrl-d-to-exit-with-y-n-prompt-like-ipython/105487/8 "2023-10-28T09:25:30Z")

</div>

> [@bert](#):
>
> `julia> Type ^D again to exit.`

Julia doesn’t do this by default, what version of Julia are you on?

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [October 28, 2023, 12:53pm UTC](https://discourse.julialang.org/t/confirm-ctrl-d-to-exit-with-y-n-prompt-like-ipython/105487/9 "2023-10-28T12:53:02Z")

</div>

> [@bert](#):
>
> ```julia
> Do you really want to exit ([y]/n)? 
> 
> ```

You also misread this.

They want.

```julia
Do you really want to exit ([y]/n)? 

```

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 28, 2023, 1:14pm UTC](https://discourse.julialang.org/t/confirm-ctrl-d-to-exit-with-y-n-prompt-like-ipython/105487/10 "2023-10-28T13:14:33Z")

</div>

> [@bert](#):
>
> Currently Julia does this:

I was reading this

---

<div class="post-metadata">

**Author:** ![bert](https://avatars.discourse-cdn.com/v4/letter/b/9e8a1a/32.png) [@bert](https://discourse.julialang.org/u/bert)\
**Post date:** [October 28, 2023, 2:10pm UTC](https://discourse.julialang.org/t/confirm-ctrl-d-to-exit-with-y-n-prompt-like-ipython/105487/11 "2023-10-28T14:10:36Z")

</div>

The issue isn’t that I’d accidentally press ctrl-D — I’d almost certainly ever press it intentionally — but rather that I’d have some old REPL session open in terminal that I hadn’t used in a while, I’d come across it and say “I don’t need this anymore, let me exit out” and then as soon as I did I’d say “oh shoot I _did_ still want something from that REPL”. The confirmation prompt is to give me a chance to think twice.

---

<div class="post-metadata">

**Author:** ![nicolas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nicolas/32/26439_2.png) [@nicolas](https://discourse.julialang.org/u/nicolas)\
**Post date:** [November 1, 2023, 2:01am UTC](https://discourse.julialang.org/t/confirm-ctrl-d-to-exit-with-y-n-prompt-like-ipython/105487/12 "2023-11-01T02:01:10Z")

</div>

Coming from Stata, I am so used to CTRL-D for executing lines of code that I have created a shortcut in VScode that does it. I exit Julia by accident every time I update my system and forget to setup my shortcuts. I would love this feature.

---

<div class="post-metadata">

**Author:** ![rfourquet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rfourquet/32/3610_2.png) [@rfourquet](https://discourse.julialang.org/u/rfourquet)\
**Post date:** [November 1, 2023, 9:28am UTC](https://discourse.julialang.org/t/confirm-ctrl-d-to-exit-with-y-n-prompt-like-ipython/105487/13 "2023-11-01T09:28:07Z")

</div>

> [@bert](#):
>
> I think it’ll just train me to double-tap `Ctrl-D`, which can be destructive if using a Julia shell that’s not using my `startup.jl`

> I think it’ll just train me to double-tap `Ctrl-D`, which can be destructive if using a Julia shell that’s not using my `startup.jl`

That might be an argument in favor of having the `confirm_exit` option on by default.  
Also, you can also press `Ctrl-D` twice in ipython to exit, so I actually never press `Ctrl-D` followed by `y<Enter>`, because it’s less direct than double `Ctrl-D`. So having the option to type `y` doesn’t help me in avoiding risking quitting the shell.

I would be fine having the same UI as ipython (where double `Crtl-D` is a hidden option), but would be reluctant to remove the possibility to type `Ctrl-D` twice to exit.

---

<div class="post-metadata">

**Author:** ![bert](https://avatars.discourse-cdn.com/v4/letter/b/9e8a1a/32.png) [@bert](https://discourse.julialang.org/u/bert)\
**Post date:** [November 1, 2023, 2:58pm UTC](https://discourse.julialang.org/t/confirm-ctrl-d-to-exit-with-y-n-prompt-like-ipython/105487/14 "2023-11-01T14:58:45Z")

</div>

Sure, I’d be fine with that

---

<div class="post-metadata">

**Author:** ![filchristou](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/filchristou/32/26760_2.png) [@filchristou](https://discourse.julialang.org/u/filchristou)\
**Post date:** [November 3, 2023, 7:16am UTC](https://discourse.julialang.org/t/confirm-ctrl-d-to-exit-with-y-n-prompt-like-ipython/105487/15 "2023-11-03T07:16:19Z")

</div>

vim users might also relate. especially if you run the REPL inside terminal mode.

---

<div class="post-metadata">

**Author:** ![jsjie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jsjie/32/22477_2.png) [@jsjie](https://discourse.julialang.org/u/jsjie)\
**Post date:** [September 19, 2024, 9:20am UTC](https://discourse.julialang.org/t/confirm-ctrl-d-to-exit-with-y-n-prompt-like-ipython/105487/16 "2024-09-19T09:20:37Z")

</div>

Sorry for reviving this old topic, but recently I often incidentally hit Ctrl-D, and I strongly wish to remove the possibility to type Ctrl-D to exit, either once nor twice.  
The reason is that `Infiltrator.jl` uses Ctrl-D to continue. The case I met so often these days is roughly like the following.  
I find a bug, and when debugging, I open two terminals, then I run in each terminal a task that different in settings, but with the same breakpoints.  
I have some idea, so I use `@exit` to leave this debugging, and add new breakpoints.  
I run the task again in the first terminal, and find that I need to skip 3 or 4 times (because the breakpoint is in a loop) until the bug occurs.  
I need to, in the second terminal, hit Ctrl-P to evoke the last command, hit Enter to run it, then hit Ctrl-D 3 or 4 times to get to the same place. However, I forget to hit Ctrl-P and Enter, and with hitting Ctrl-D 3 or 4 times, I leave the REPL. Now I have to open it again and wait for the long long precompilation to continue my debugging.  
It is clear that in this case, allowing hitting Ctrl-D alone to leave the REPL will lead to the same problem, whether you need to hit it once or twice. Only forcing hitting another key to leave can save me. A better solution may be that `Infiltrator.jl` uses another shortcut to continue, but I doubt whether such a change is possible, since it has been widely used, and it is a change that will affect nearly everyone using it.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [September 19, 2024, 9:28am UTC](https://discourse.julialang.org/t/confirm-ctrl-d-to-exit-with-y-n-prompt-like-ipython/105487/17 "2024-09-19T09:28:27Z")

</div>

> [@StevenSiew](#):
>
> It is very hard to type “CTRL-D” by accident.

I have Ctrl-d mapped to select words with multiple cursors (I believe I learned this from SublimeText way back), and use that _constantly_. If focus is in the REPL instead of the editor, bam.
