# Nice weird feature on pasting julia\> code

**URL:** <https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020>\
**Category:** New to Julia\
**Created:** [September 16, 2018, 3:53pm UTC](https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020 "2018-09-16T15:53:32Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [September 16, 2018, 3:53pm UTC](https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020/1 "2018-09-16T15:53:32Z")

</div>

on macos and linux, copy

```julia
julia> x=2

julia> x + 1

```

into the copy-paste buffer.

obviously, this should not be pasted into a running REPL, because each line starts with `julia> `.

**except** , the REPL is smart enough to recognize this somehow. in fact, on paste, the paste-buffer `julia> ` does not show up on the screen.

typing the code into the REPL does not work. the 'julia\> ’ becomes visible, and then it does not work.

so, how does this feature work? is this special paste functionality in the julia REPL?

---

<div class="post-metadata">

**Author:** ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)\
**Post date:** [September 16, 2018, 4:13pm UTC](https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020/2 "2018-09-16T16:13:32Z")

</div>

How did I not notice that this works until now? This wants to be part of the discourse FAQ/PSA, amazing.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 16, 2018, 4:17pm UTC](https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020/3 "2018-09-16T16:17:28Z")

</div>

> <https://github.com/JuliaLang/julia/pull/17599>
>
> It is common to encounter example code that is posted with the REPL prefix inclu…ded (typically \`julia\>\`). This occurs in manual, doc tests and in forum posts etc. Usually one wants to quickly run this code in the REPL but then has to manually remove all the prompt prefixes first which can be a bit annoying.
> 
> This PR simply checks if the statement being evaluated in the REPL starts with the REPL prefix and in that case removes it.
> 
> As an example pasting this code block:
> 
> \`\`\` jl
> julia\> const x = 1;
> 
> julia\> function foo(x)
> return x + 1
> end;
> 
> julia\> type X
> x::Int
> end;
> \`\`\`
> 
> will be equivalent to pasting it without the \`julia\>\` prefixes.
> 
> This is also implemented for the other REPL modes.
> 
> fixes https://github.com/JuliaLang/julia/issues/16383

[![](https://global.discourse-cdn.com/julialang/original/3X/7/6/76ea80311e698b1c22211ca0e87c49859dd2cd17.jpeg "JuliaCon 2017 | OhMyREPL.jl: This is my REPL ... | Kristoffer Carlsson") ](https://www.youtube.com/watch?v=dDjH26p2BhE&t=861)

[The Julia REPL · The Julia Language](https://docs.julialang.org/en/v1/stdlib/REPL/#The-Julian-mode-1) last paragraph.

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [September 16, 2018, 4:34pm UTC](https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020/4 "2018-09-16T16:34:56Z")

</div>

this is a **great** feature addition. love it. alas, why did it now work when I typed it:

```julia
julia> julia> x=2
> (generic function with 1 method)

julia> julia> x=2
> (generic function with 1 method)

```

similarly. it does not work with julia source code:

```julia
$ cat test.jl
julia> x=2

julia> x=x+1

julia> println(x)

^D

$ julia test.jl
ERROR: LoadError: UndefVarError: x not defined
Stacktrace:

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 16, 2018, 4:36pm UTC](https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020/5 "2018-09-16T16:36:17Z")

</div>

It is only active when pasting (and the terminal supports detecting paste, [bracketed paste mode](https://cirw.in/blog/bracketed-paste)).

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [September 16, 2018, 4:37pm UTC](https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020/6 "2018-09-16T16:37:10Z")

</div>

great. mille grazie. I did not know that terminal-paste-detection-passthrough existed.

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [September 16, 2018, 4:45pm UTC](https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020/7 "2018-09-16T16:45:55Z")

</div>

> [@kristoffer.carlsson](#):
>
> [The Julia REPL · The Julia Language](https://docs.julialang.org/en/v1/stdlib/REPL/#The-Julian-mode-1)

This is a good reminder to take a look at the doc. I have never really spent the time in going through the key bindings before.

I found some surprises for myself.

1. Setting a mark and coming back to it (C-space and C-x C-x)
2. Moving forward/backward by word (M-f and M-b)
3. Transpose characters! (C-t, and I had fun C-t all the way to move a char to the end of line)
4. etc.

But some functions don’t work (I’m using Mac):

1. M-left/right arrow does not indent/deindent. Instead, it moves cursor left/right a word similar to M-f and M-b
2. C-/ does nothing but C-\_ works properly.

We should also add `]` for entering the package manager mode in the doc.

---

<div class="post-metadata">

**Author:** ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)\
**Post date:** [September 16, 2018, 4:46pm UTC](https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020/8 "2018-09-16T16:46:11Z")

</div>

Doesn’t `Base.REPL.enable_promptpaste(::Bool)` needs to be replaced by `REPL.enable_promptpaste(::Bool)` in julia 1.0 doc?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 16, 2018, 4:50pm UTC](https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020/9 "2018-09-16T16:50:26Z")

</div>

Yes. But the whole option should probably just be removed.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [September 16, 2018, 4:53pm UTC](https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020/10 "2018-09-16T16:53:24Z")

</div>

As in just enable it unconditionally?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 16, 2018, 4:56pm UTC](https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020/11 "2018-09-16T16:56:47Z")

</div>

Yeah, I don’t think anyone has ever disabled it. I think the only reason to disable it is if you wanted to define `>` using the infix method which doesn’t seem too likely:

```julia
julia> julia> x = 3
> (generic function with 1 method)

julia> "foo" > :bar
3

```

---

<div class="post-metadata">

**Author:** ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)\
**Post date:** [September 16, 2018, 5:11pm UTC](https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020/12 "2018-09-16T17:11:57Z")

</div>

BTW if I want to have my own prompt and use this feature I have to use something like:

repl.interface.modes[1].prompt="julia\> #=$VERSION=# "

Then I will have (not very nice prompt):

```julia
julia> #=1.0.1-pre.4=# a = 3
3

```

And if I copy+paste it works (but is even more ugly):

```julia
julia> #=1.0.1-pre.4=# #=1.0.1-pre.4=# a = 3
3

```

I would rather see something more flexible:

```julia
# maybe julia[any string without '>']>
julia 1.0.1-pre.4>
# or maybe julia([any string without '>'])>
julia( 1.0.1-pre.4 )>

```

---

<div class="post-metadata">

**Author:** ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)\
**Post date:** [September 16, 2018, 5:17pm UTC](https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020/13 "2018-09-16T17:17:56Z")

</div>

This one also doesn’t work:

```julia
(v1.0) pkg> add package
# copy+paste it
julia> (v1.0) pkg> add package

ERROR: syntax: missing comma or ) in argument list
# or 
(v1.0) pkg> (v1.0) pkg> add package

ERROR: expected command. instead got [(v1.0)]

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 16, 2018, 8:16pm UTC](https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020/14 "2018-09-16T20:16:24Z")

</div>

It is only active for `julia>`.

---

<div class="post-metadata">

**Author:** ![Ralf\_Dietrich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralf_dietrich/32/5643_2.png) [@Ralf\_Dietrich](https://discourse.julialang.org/u/Ralf_Dietrich)\
**Post date:** [April 14, 2023, 11:27am UTC](https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020/15 "2023-04-14T11:27:54Z")

</div>

I just tried if this works at all under WIN11 (Julia 1.8.5) and failed.

![image](https://global.discourse-cdn.com/julialang/original/3X/2/4/248767e05e514c7ea3616a6e59b8f016457f56a3.png)

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [April 14, 2023, 1:49pm UTC](https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020/16 "2023-04-14T13:49:17Z")

</div>

Older windows terminals are too broken for this to work, strongly recommend using a newer terminal (which is the default in newer windows versions).

---

<div class="post-metadata">

**Author:** ![Jordan\_Cluts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jordan_cluts/32/13753_2.png) [@Jordan\_Cluts](https://discourse.julialang.org/u/Jordan_Cluts)\
**Post date:** [April 14, 2023, 7:36pm UTC](https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020/18 "2023-04-14T19:36:35Z")

</div>

I just tried it using the (relatively) new “Windows Terminal” and it still did not work. I assumed this is what you meant (as opposed to the old cmd or powershell terminals). Is Windows Terminal the new terminal you meant or is there something else instead?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [April 14, 2023, 8:48pm UTC](https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020/19 "2023-04-14T20:48:22Z")

</div>

It wasn’t working for me [a year ago](https://discourse.julialang.org/t/discussion-on-improving-julia-repl-for-beginners/82933/8) in Win 11 PowerShell, and it still doesn’t work with the latest PS update.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [April 14, 2023, 11:37pm UTC](https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020/20 "2023-04-14T23:37:29Z")

</div>

Hmm. @kristoffer.carlsson do you know why it doesn’t work on Windows?

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [April 15, 2023, 12:51am UTC](https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020/21 "2023-04-15T00:51:39Z")

</div>

See [bracketed paste in conhost · Issue #395 · microsoft/terminal · GitHub](https://github.com/microsoft/terminal/issues/395). It should be supported.

[Next page](https://discourse.julialang.org/t/nice-weird-feature-on-pasting-julia-code/15020.md?page=2)
