Navigating within Julia REPL?

"/home/grimm"

julia> 
julia> using Pkg

julia> Pkg.generate("HelloWorld")
  Generating  project HelloWorld:
    HelloWorld/Project.toml
    HelloWorld/src/HelloWorld.jl
Dict{String, Base.UUID} with 1 entry:
  "HelloWorld" => UUID("0f36ea27-3fa5-45e8-8aed-a1573f2015cd")

(HelloWorld) pkg> activate ~/HelloWorld
  Activating project at `~/HelloWorld`


(HelloWorld) pkg> instantiate
  No Changes to `~/HelloWorld/Project.toml`
  No Changes to `~/HelloWorld/Manifest.toml`
Precompiling project...
  1 dependency successfully precompiled in 1 seconds

I’m learning to navigate within the Julia REPL (using Linux Mint) - for ex - creating a simple pkg above works fine. I know to use pwd() to be sure I’m in the right directory and cd(β€œpath to files”) - but if I want to say, change the text inside the HelloWorld.jl file(located in the src directory) I have to exit REPL, back to Linux file system, open HelloWorld.jl file with my text editor, then re-enter Julia REPL. This all works, but wondering if it’s possible to somehow edit that .jl file without leaving the REPL? I imagine I would need a text editor or vim or nano - is there anything like that actually IN the REPL? Or can I switch to shell and get into Linux file sys that way? Thanks for your time guys.

1 Like

Can you not run a text editor on the HelloWorld.jl file as a separate process, and just move your mouse to switch focus between the two? Or are you not running a windowing system?

VSCode is recommended by many and me.
Of course it has its own learning curve. Perhaps it’s better to start as you do, you may use multiple terminals, one with Julia, another with your editor, another for commands,… and when you feel good you may start again with VSCode.

Another important recommendation is to use Revise.jl , this is to overcome most of the problems if you need to reload a Julia file in the REPL which you have changed.

1 Like

Not interested in using VS Code, but will look into Revise.jl - thanks.

1 Like

There are ways to get it done with multiple terminals / windows. But I don’t like going to the mouse and prefer doing everything from the terminal. REPL is running in the terminal and using Linux commands like pwd and cd, and hitting the semicolon opens my actual Linux shell - I think I can get in and out of nano or vim that way. Thanks for your suggestion though.

Julia does have a configurable edit function.

help?> edit
search: edit @edit timedwait endswith redirect_stdio

  edit(path::AbstractString, line::Integer=0, column::Integer=0)

  Edit a file or directory optionally providing a line number to
  edit the file at. Return to the julia prompt when you quit the
  editor. The editor can be changed by setting JULIA_EDITOR,
  VISUAL or EDITOR as an environment variable.

  See also define_editor.

  ──────────────────────────────────────────────────────────────

  edit(function, [types])
  edit(module)

  Edit the definition of a function, optionally specifying a
  tuple of types to indicate which method to edit. For modules,
  open the main source file. The module needs to be loaded with
  using or import first.

  β”‚ Julia 1.1
  β”‚
  β”‚  edit on modules requires at least Julia 1.1.

  To ensure that the file can be opened at the given line, you
  may need to call define_editor first.

Also in a Linux terminal you can press Ctrl-z to suspend Julia. Then edit your file or do whatever. Then type fg to foreground your Julia process again. Also see the Bash jobs command. Combined with Revise.jl this creates a nice workflow.

Also check out the Unix utilities screen and tmux.

What text editor do you use?

1 Like

I like to use really simple text editors like xed or nano, rather than something like VS Code so I’m focused on learning the language and not distracted by using a mouse or IDE. Since asking this question I see how easy it is to hit the semicolon key and get into the my Linux file system to use those editors. But thanks - you gave me a lot of other options to try out!

On most OSs you can use ALT+TAB to switch between windows, so need for a mouse and you can just open a second terminal and edit your code in whatever editor you like there.

1 Like

Thanks - good shortcut, but I’ve figured out since posting this question that when in REPL, if I just open shell with semicolon key I can navigate between Linux file system and REPL without windows. Great feature from the Julia team - works with Linux OS anyway.

I highly recommend this workshop to learn nice tips and tricks for working in the REPL. https://github.com/miguelraz/REPLMasteryWorkshop

There is also a recording available on youtube.

2 Likes

How about vim?

3 Likes

Thanks Miguel - will do. Also - just listened to your talk from April 2022 on Talk Julia.

You’re absolutely right to recommend Vim to me - I know that for those who like doing as much in the terminal as possible, Vim is the way. I just haven’t been able to fight the learning curve and stay with it enough to get proficient - but I’m going to learn it. Thanks for the push,

For someone who wants to stay as log as possible in the terminal, I’d really second this recommendation.

The idea is that you’d launch the multiplexer in your terminal (either screen or tmux; the latter seems more popular these days), and then you get something akin to multiple β€œtabs” or β€œpanes”. You’d open your editor (xed or nano if you’re used to them) in one tab/pane, and the Julia REPL in another. The multiplexer lets you easily switching between tabs/panes.


More advanced editors, such as Emacs (but maybe vim can as well; I just don’t know) can act as sort of a multiplexer in themselves. That is to say you can open a terminal within Emacs, and switch between editing files or interacting with the terminal seamlessly, only using builtin commands. Of course this again is something to learn, but there are many collateral benefits. For example, the ability to interactively select code from a source file and evaluate it inside the Julia REPL (like you’d do in VScode)

2 Likes

Going to experiment with Revise.jl - thanks. Really, there are so many great Julia packages I’m still unaware of and learning about here.

2 Likes

Also possibly check out our Shelly.jl - no semicolon required…

2 Likes

That’s great - out of habit I kept trying to us β€˜ls’ - now I’ll be able to.

Why is lsa and lla not activated yet? It seems to work fine (on windows).