Vim mode in REPL command line

repl

#1

I’m not talking about a julia mode for vim - that exists and is lovely. I’m talking about the command line in the REPL - so that when you can escape partway into a long command you can use vim-flavored actions to change your REPL input. It is massively powerful if you have vim in your veins.

I understand from this ancient issue that Julia gave up GNU Readline long ago, and it was left to an “intrepid” developer to build. I’ve looked a bit at julia/stdlib/REPL to find the hooks and approach to do this, but have to ask:

Is someone already doing this? What is involved in doing this? What will make it challenging? It’s an itch I’d like to scratch, but I’ve got work to do (we all do) as well.


#2

At some point I was also interested in this feature. But now I am happy with vim-slime: I write my code in vim and with vim-slime send it to the REPL.


#3

This isn’t a real solution, but I’ve started using Revise.jl by default especially as we face even longer compile times in 0.7, and I think Revise.jl helps with this sort of thing as well. It makes it possible to spend much more of your time editing your code in vim rather than typing anything into the REPL. I pretty much only ever do simple function calls in the REPL.


#4

Maybe it’ll come down to that for now, or slime-ing longer commands over to the REPL. But in R, my usage pattern can involve REPL commands that are three lines long, mostly strung-up dplyr stuff. It’s useful to see what works on the data before committing to code. A VIM mode is really useful to tweak those long lines, plus the “muscle memory” issue.

It ain’t gonna write itself, and sadly there doesn’t seem to be a huge demand for it. I need to clear some other projects out before committing to creating/maintaining a public project.


#5

Yeah, doing vim work always comes with the obstacle of the awful vim script. Neovim has been forging ahead quite nicely, however, and I think that by now it is possible to do a lot of things in Python.


#6

Also, I just found this. I wonder if it would be worth resurrecting? Although honestly, this is one of those cases where Python actually seems more appropriate than Julia, since we really are talking about scripting here (fast startup times are very important, in my experience). Obviously Julia integration is important for using the REPL though.


#7

Hmm, what I have in mind was outside of a vim or nvim. I was thinking of the line editor within the REPL, where keystrokes edit what’s on the julia> line. Aiming for something like bindkey -v in zsh. The issue linked above implies that the plumbing is available in stdlib/REPL/* to build an extension so this is possible. The issue above talks about embedding nvim into the line, I think, but that seems like overkill?


#8

The thing on my wishlist is an “advanced terminal”, but I’ve never even seen anything like that being worked on. What I have in mind is something that behaves as much like gnome-terminal as possible but can support things like plotting and pixel addressable graphics. I would be open to using VSCode or Atom this way, but they are simply still too far away from this paradigm: they are still very frustrating to use and it’s still very difficult to completely eliminate all the GUI elements of them.

I suppose a Linux window manager would be the closest thing to what I’m imagining, but I haven’t taken the time to really dive into one yet.


#9

What would be in that advanced terminal? I know you’ve seen UnicodePlots.jl, which heads in that direction.

I know you don’t mean a CLI helper like this, so I’m not sure what else would go in it. I just want to be able to type wwwlllr7 to change a number to 7 and rerun. Come to think of it, VI mode for discourse would be nice too.

As discussed in another thread, all of this would have to work through a remote SSH, too.


#10

The idea in my head is all the advantages of an IDE (especially plotting and interactivity when you need them) but none of the other GUI features. In other words, I do really like that in an IDE you can get a pretty plot, maybe with a slider or something and things like table viewers, but I’d want to cut out all of the other GUI baggage that comes with it. In other words, the philosophy would be “No GUI ever, except when it’s actually useful”. Modern IDE’s seem more like their philosophy is “Get in the way of everything, GUI the hell out of the user”. And no the CLI helper was not the sort of thing I meant.

Admittedly this isn’t something I’ve carefully thought through, so maybe it’s a silly idea.


#11

Gotcha. So far linux and tmux and the i3 tiling window manager do enough of that for me; I know you’re on similar rig. I put plots on a floating window above the tiles. In a way, linux is my IDE.

I like your idea. Another way to frame it would be to have one or more packages of “helper” GUI applications that would launch from the REPL when you needed to see a table, or a code hierarchy, or debugger, much the way that Plots does. Authors could implement one idea at a time that they liked from the IDEs.


#12

Yeah, I’m using tmux and nvim in Ubuntu. I’ve checked out i3 a little bit but, like I said, I just haven’t invested the time in it yet to see if it’s really something I’m looking for.

Here’s my vision: You boot up your operating system and are dumped into a blank terminal running something akin to tmux. If you want to go to a web page, you type firefox julialang.org or if you want to search duckduckgo you do firefox -d "julia lang" and embedded in the terminal you will get a piece of a firefox window that you can use in the usual way with tabs and everything, but which you can easily just go back into the terminal from with something like vim modes and commands, and you can also resize it so that you have your browser and terminal side by side. At any time you can open a new tmux tab and switch between them. I envision plots, data viewers and interactive debuggers working in a similar way.

Maybe I’ve just described i3, but it didn’t quite seem like it from what I was seeing.


#13

Ok - so if you type firefox julialang.org in a terminal now, it’ll open that URL in a new tab wherever you have firefox running, or launch a window in a random place.

The only difference with i3 or any tiling wm is that would put the window in a predicable place, and you could resize the tiles with keystrokes. There’s no wasted space, no background image, no mousing around.

I like the idea of julia helper applications - a slick table viewer is the main thing that comes to mind. Not sure if I’d even use that. The GUI builders seen on IDEs come to mind as well, but not for Julia or numeric/backend programming.

I think emacs or vim would do everything else. Looking at RStudio, I also see a help file viewer, workspace viewer, git, package manager, lots of things that are a single cli command.


#14

Yeah, the current situation is not terrible, which is probably why it’s been status quo forever now.

Sounds like I should put in the time to try out i3 at some point.

Think I’ll wind up using sway as I am looking forward to the future with Wayland :smile:


#15

Depending on the use case, jupyter notebook is a nice option for interactivity + vim mode.


#16

Oh, look at that, there’s a vim mode for jupyter.


#17

A while back I created an unregistered package that uses vim for text editing in the REPL, specifically, it’s meant for LaTeX editing for i3 users. https://github.com/chakravala/JuliaTeX.jl

Eventually I plan to explain more details what it’s for, but right now it’s still a “secret”.

But essentially, this is part of an interface that will allow LaTeX editing with vim in the Julia REPL, more generally, there will be an associative database for organizing references and dependences of mathematical defintions and theorems and LaTeX parsing too.

Vim just happens to be a way of interfacing with it in the Julia REPL. Basically, you can just write your text buffer into a temporary file in the OS and then launch vim for the editing, and Julia can launch a PDF viewer automatically to help with the display of it. Not ready for use yet, it will be announced when ready.

This is going to provide a completely new workflow for editing LaTeX files in Julia with vim, but not ready yet.

Try it! it’s not as difficult as it looks, it’s very easy. Even got my dad to use it.

Also, sway is really easy to have on your system if you have i3. I have both installed, and can switch.


#18

Slightly off-topic, but how about integrating, perhaps optionally

into the Julia REPL? As far as I can see, for this one would need to dig into julia/stdlib/REPL?


#19

I was looking into it more yesterday and this is indeed what I’m going to do! It does look like sway or i3 will allow me to do much of what I’ve been imagining, I’m pretty excited.

So far I haven’t been able to actually run sway (except in a window in GNOME), I keep getting “Can’t open wayland socket” (at least one 1 of the machines I tried it on I was already running Wayland GNOME so I knew Wayland was set up properly). The github documentation for Sway hasn’t been too helpful yet, if you can point me to any set up guides I would be hugely appreciative.


#20

What OS are you using? The Arch Wiki has some information https://wiki.archlinux.org/index.php/Sway

Sway doesn’t work well (or at all) under VirtualBox.

Have you previously installed and used i3 before? If so, you can just copy your config folder. Otherwise, you can use the defaults provided by sway. It’s easy to install if you use the Arch Linux package manager.

Not sure about GNOME with Wayland, but for sway just type sway into your TTY instead of startx to launch.