Skip to main content
523

October 14th, 2022 × #neovim#vim#lua

Supper Club × Neovim, Lua, RPC and Twitch with TJ DeVries

TJ DeVries discusses Neovim, Lua integration, and the difference between Neovim and Vim.

or
Topic 0 00:00

Transcript

Announcer

I sure hope you're hungry.

Announcer

Oh, I'm starving.

Announcer

Wash those hands, pull up a chair, and secure that feed bag, because it's time to listen to Scott Tolinski and Wes Bos attempt to use human language to converse with and pick the brains of other developers. I thought there was gonna be food, so buckle up and grab that old handle because this ride is going to get wild.

Announcer

This is the Syntax supper club.

Guest 1

Welcome to syntax, the podcast with the tastiest web development treats Out there, we've got a supper club for you today with TJ DeVries. We're gonna talk about, Neo Vim, something he works on as well as, probably anything else that that pops up is gonna be interesting, so buckle up.

Guest 1

We are sponsored by 3 awesome companies today.

Sponsored by 3 companies

Guest 1

Gatsby, which is the fastest way to build a headless website, Hasura GraphQL API on your existing database and fire hydrant, innovative incident response. We'll talk about all of them partway through the episode. So

Guest 2

welcome, TJ. Thank you so much for coming on. Yeah. Thanks for having me. Really excited to chat, and I love getting to just chat about tech stuff and kneel them and excited to see where we go. We are. We were just before the episode, we were talking about,

Topic 2 01:25

Guest is Dutch and from Michigan

Guest 1

being Dutch and from Michigan, which is, like, a 100% overlap with the interests of Scott and I. So that's a fun little One little pregame.

Guest 2

It's a small world sometimes. You know? What? You guys know my little town I live in? Wow. That's pretty exciting. You know?

Guest 1

It's it's actually funny how often we have either Canadians or people from Michigan on the show. It seems like half the guests So far, I've been been that.

Guest 2

Yeah. Well, you know, I mean, I like winter, but you're definitely inside more during the wintertime. So maybe there's some correlation They're of, spending time in your basement huddled up with a nice blanket and a coffee, and you're like, well, it's dark out. I guess I'll just write some Yeah. People are too busy hiking out here to learn how to program where I'm at. Yeah. They're like, we've got fun things to do, like mountains good stuff. You know? Mhmm. So you wanna give us a quick rundown of who you are, which do, all that good stuff? Yeah. So, like, like I was introduced, I'm TJ.

Guest 2

One of the main things that I like to do is I work on a lot of different open source projects, particularly, like, related to Neovim, although not exclusively. I've done a lot of work in Neovim core, especially around LSP integration and Lua integration, and we can talk about those. I think those are some of the really fun and exciting features for Neil Vem. And a few years ago, I started doing live coding on Twitch, thanks to the Primagen, and, he told me that I should just give it a go and say I said okay. And it's been a blast and super sort of interesting way to build a new community and friends along the way of of building stuff. You know? You get to know people a lot more than just from, like, pull request comments and things like that. So it's been It's been super exciting.

Guest 2

And so yeah. So those are those are the big things that I I've been doing these days, and I I really like working on developer tool things.

Guest 3

So, I mean, maybe we should get right into the Vim stuff. I know we talked a little bit about Vim with, the private gen when he was on. And Wes and I are neither of us are necessarily VIM users, but we are VIM competent. We we know how to use it at the super covering. Yeah. Or yeah. Yeah. I I guess the the biggest questions that I think the audience might wonder, and, you know, I might wonder this myself, is Vim and Neovim.

Guest 3

Are they 2 separate things? Is 1 a layer on top of another? What's the difference between Vim and Neovim?

Topic 3 03:45

Difference between Vim and Neovim

Guest 2

Yeah. This is a good question.

Guest 2

Neovim is actually a fork of Vim.

Guest 2

So it's not like a rewrite, and it's not that we just wanted to do, like, feature for feature exactly what Vim had. But, a few years ago, Neovim forked Vim at around Vim 7.4.

Guest 2

And Neovim, even now, we Still do a lot of, like, patching of you know, sort of porting over patches from VIM into Neovim. So we still share, like, a lot of code, Which is really good for things where if there's, there's, like, a lot of history of how you would expect different commands and movements and all these things. And if you go into different sort of Vim emulators, right, inside of different editors, they don't do Exactly what you think that they should do. Right? They often do most of them or they cover some 80% coverage.

Guest 2

So Neovim is really, in a lot of ways, Exactly the same as Vim for sort of your introductory experiences.

Guest 2

And even to the point of we still have VIM script and we can run VIM script Plug ins. And so if you had plug ins in VIM, you can run most of those in Neovim.

Guest 2

Over time, VIM and Neovim have diverged more.

Guest 2

Neovim introduced Lua And a lot of different sort of APIs style bindings that VIM doesn't have, and VIM has been going down a different route.

Guest 2

Introduced the 9 script, which is sort of like, the next version of VIM script. And so there are some incompatibilities today, but many Plug ins, if they're targeting both, it's possible to target both.

Guest 2

But in terms of, like, when you open up the editors and when you move around and do those things, they'll be Literally the same, and most likely, they're running over exactly the same code paths for VIM and Neovim. And, we even send features and patches back To VIM, from Neovim's side, if we find some bug or we find some feature that seems to make sense, you know, we talk about those in the issue tracker, and then sometimes Bram or someone else will implement those inside of him as well. So we still have a really, at least at the maintainer level, a really kind and nice, Productive relationship between the 2 projects even if sometimes, people in the comment section Mhmm. Are a little more antagonistic.

Guest 2

And, I mean, it's the Internet. Right? So people like to do that. And I was just like, do you not understand? Like, we're friends. You know, like, you can be 2 projects, and we can be friends still. That's cool. So what

Topic 4 06:15

Why Neovim added Lua integration

Guest 1

was Vim like, what is Vim written in originally? And, like, why do you choose to start

Guest 2

Rewriting it or adding additional features in Lua? Yeah. So Vim is written in c, and Neovim is primarily also written in c because it's a fork of Vim.

Guest 2

We chose Lua inside of Neovim for a variety of reasons. The primary reasons being Lua is incredibly easy to integrate with c. So you can pass around and, in fact, even write Lua code that directly accesses c functions, and it has a really nice FFI boundary and all these really interesting, easy ways to tightly integrate them. An easy, simple example of that is we can actually take, like, a Lua function, and we can pass that into c And, like, store that in a list of stuff so that you could call that function on some certain command, right, inside of them. So, like, those are super easy to interoperate even though, like, the inner part of Neovim is written in c, and you're passing around this Lua function. They play together super nice.

Guest 2

The other part is Neomim is a pretty small in terms of, like, resource consumption editor, and Lua is a very tiny language. So It doesn't quadruple or 10 x or a 100 x the size of the, like, the binary that we end up shipping by including some other language. It just is small and fits inside.

Guest 2

And then the last part is, especially with Lua 5.1, which is the version of Lua that we have inside of Neovim, It is a finished version as in there will never be any changes. It's just done. So code that you wrote for Lua 10 years ago will still run-in Lua today. That's good for the kinds of things that you would like to have for your editor. Right? Like, you just Write it, and then it you know it's gonna work forever.

Guest 2

And there's one final last little piece of it is that Lua 5.1 has a really incredible Project associated with it called LuaJit, maintained by Mike Paul. And Mike Paul has often been called a robot from the future because LuaJit is just An incredibly fast and elegant and beautiful JIT compiler that basically makes Lua as fast as, like, writing steam Sometimes if you're being smart about how you're using it, which is incredible. Uh-huh. So so those features altogether sort of why we brought Lua in. There are features inside of Neovim that are written in Lua today. For example, the language server client inside of Neovim that's built in and ships By default with Neovim is all written in Lua. So we didn't have to write any c code or, like, worry about that or anything. We used Lua. It's super easy to write and extend, and then so there are features being built inside of Neovim core in Lua, but Lua's sort of primary use case for a lot of people is that it's a much, in my opinion, more elegant and simple way to configure Neovim and to write plug ins in Neovim since Lua is sort of Sort of like a real programming language that you could learn and have a use for outside of just Neo. Okay. That's cool because I I was gonna ask that we had so this audience is primarily web developers,

Topic 5 09:27

Benefits of Lua for non-web devs

Guest 1

primarily JavaScript, TypeScript, Ruby, PHP, that type of stuff. And, like, recently, we've been having a lot of people on the podcast who write language that are not, like I'm I'm putting quotes at your web development languages here. And then you start to see things like like lua, and we had Zig and, a lot of rust and stuff like that. And there I guess the benefit to that is you get the the speed and the the size and the all those stuff of c, but it's It's a much nicer language to write. I'm just looking at examples of it. I have never I've written a lot to see in my life in school, and that was awful.

Guest 2

And then and then I see this. I'm like, this looks a lot nicer. Is is that the main draw? Is there stuff with memory as well that It's different. Yeah. I think, I mean, you're a lot safer writing Lua than you are writing c. Right? Like, you can just accidentally access a bunch of memory that you're not post 2 and c, that's just not, like, a thing in Lua, generally speaking. I mean, it's possible to do just like it's possible to do in other languages, but you kinda have to be, like, attempting to do that. Right? You're like, oh, load up some FFI thing and do all this other stuff and then intentionally break it. You're like, sure. Yes. That's possible. But, I mean, in terms of, like, just writing regular everyday code, You're not gonna, like, crash, which is great. The other thing too is Lua is is, like, a very small and simple language. So you could probably get up to speed on writing Lua if you've written other code, right, of course, in, like, 30 minutes or less. Like, It's it's very small, very simple. One of the, like, sort of features of Lua is that it's sort of less is more. There's only Basically, the data types are booleans, numbers, strings, functions, tables, and coroutines. I think I I listed them all. And and nil, and that's it. So so there's nothing else that exists. You wanna put something in a table, like, in a list, you put it in a table. You wanna make a map, you put it in a tape. Like, it's all the same, And so that makes it really great for people who wanna do something simple with their editor. Right? I wanna change a few options or wanna write some small little script for myself. Well, cool. You can get up to speed on that in 30 minutes. You don't have to learn, like, well, how do I transpile this TypeScript to JavaScript again and get it loaded and you're like, No. That doesn't exist. That's not a difficulty for this situation. Yeah. There's a lot of things we're talking about here with Lua that You're, like, reflecting very closely on what our life life is like writing TypeScript or JavaScript.

Guest 3

Yeah. It is it's making me feel a little uneasy here. Yeah.

Topic 6 11:55

Lua simplicity compared to JavaScript

Guest 1

That's wild because, like, you think a lot of people use the podcast might think that these other languages are for people who are Transcending the languages we use and are much smarter and amazing. And then you look at the, like, docs of And, like, I could literally just let's put a manual in 1 scroll.

Guest 1

And I was like, okay, I I get it. And, like, may maybe it is worth, Learning a second people always ask that, should I learn a second language? You know?

Guest 2

It'd be kind of fun to build something in this. Yeah. And I think the the nice thing is For Lua, like, it is really simple, and it's supposed to be really straightforward to learn. And that's what you want in, like, an Extension language for a project. Right? It doesn't have all the fancy bells and whistles that you would have, like, in TypeScript. Right? There's no way to say this variable is unable to be changed. Right. Like, there's no final keyword or something or, like, there's no constant keyword. Oh, yeah. Or there's no, like, way you know? And so there's a lot Left out of the language, but that's intentional. Right? The language is designed to be the small, simple language, which maybe you wouldn't wanna build your next Startup in. Like, I wouldn't wanna build a startup in Lua. That seems weird. There's better tools for that kind of thing. But I I would wanna write a small script in Lua to Configure what happens when I write something on save so that I can easily configure my editor do exactly what I want for this Particular scenario.

Guest 2

Yeah. Yeah.

Guest 1

That's that's really cool. So one of I was reading reading Neo Vim and some of the, like, The goals of, like like, why would you fork them? And one of the goals was, so that you can create more.

Guest 1

I forget what the wording was. Adaptive UIs.

Topic 7 13:38

Neovim goal of adaptive UIs

Guest 1

Can you talk a little bit more about that? Because that has always been a hang up for me, is that I love the UI of v s code a lot more because you get a little bit more flexibility in terms of how you can display information

Guest 2

versus VIM. Is is that what you mean by that? Yeah. So there's a there's a couple things. I think there's sort of a base layer of Things that have now been added to both VIM and Neovim, including things like pop up windows inside of Neovim. So if you wanted to sort of, like, float something above the text. You can do that now. Now it's if it's rendered in the terminal, it's still going to be restricted by the fact that, you know, they have to be the same font size and other things like that, whatever. That's, You know, a terminal limitation.

Guest 2

But but those abilities to do that allow you to do really exciting things, Like, the project that I've written called Telescope NVIM, which is like a fuzzy finder for Neovim.

Guest 2

When you open up the fuzzy finder, it pops up Optionally in the middle of the screen, and it's got a few different windows. And 1 window is the list of entries, 1 is where you're typing, and then another one is a preview of the file or whatever it is. Right? So you can so you can still, like, do the kinds of things that you would sort of expect In, let's say, quote, modern IDEs or something like that, right, where you have this pop up window or whatever. So that was one of the first phases of things that Neovim was doing. But, additionally, in Neovim, GUIs for Neovim are basically just plug ins. And what I mean by that is Neovim emits Events when it wants to do something, when it wants to draw new characters on the screen, when it wants you to scroll, when it wants you to add a new window, etcetera, etcetera. Right? All of the things that are the Neovim editing experience are emitted over RPC by events. And so you could write Any program you want in whatever language you want using whatever UI tooling you want to display those things. So there exists a few pretty popular, GUIs like Neo V Day. That's written in Rust. There's one called, I think, f of them, and it's written in, like, f sharp, I think. And these can support, you know, multiple different font sizes in the same thing. Right? So, like, you're editing markdown and you do a header. It can make that text big. Right? There's nothing. Neovim just tells you where it wants you to draw the columns, but you can pick how you want those to be displayed.

Guest 2

Right? And so this whole concept It's basically like, how can we make Neovim be this thing that can be embedded and extended and used in unique and interesting ways Because we have standardized the way that we're omitting events and creating new events for new and interesting applications that we never thought would be possible Well to do before.

Guest 1

Okay. Yeah. I'm just looking at FM itself.

Guest 1

So maybe we should say For people listening to podcast, because some sometimes we just assume people know how all this stuff works is that when you use Vim or Neovim, you literally just install it as, like, a Command on your computer, and your your your GUI, your UI to actually use it is the terminal at the very basic. Right? And but then there there are other gooeys that are built,

Guest 2

I guess, to add more functionality, and f Vim is one of those. Right? Yeah. Yeah. That's exactly right. And so then instead of running it in the terminal, Neovim says, I see that I'm not being run-in a terminal. I'll just keep omitting these events about what We need to do, you know, redraw the status line, add a new window, show completions, blah blah blah, all these kind of things. Right? And FM says, I speak that language, And then it displays those for you in whatever format so desired by the author of that GUI. And so that's why I'm saying, like, GUIs are just plug ins. Like, they're completely separate, and you could install different ones and have your exact same Neovim setup in different ones. There's even there's one written in Go called, go on BIM. So there's, like, all these different ones with people exploring new ideas and interesting ways to to use NeoBIM, outside of the world. And there's icons.

Guest 2

Yeah. Honey, well, we have icons too, but yeah. Nerd font. They're usually not SVG. They're just nerd fonts. Yeah. Is that what you do? Okay. Okay. Mhmm. Yeah. Speaking of this, I I've been using something for a little bit now. LunarVim. Has that reached your

Guest 3

your, yeah, so it's a Weslutervim is, like, kind of, like, a gooey type of, like, IDE system for, Neovim. Correct? Yeah. It's like a distribution for Neil. Distribution. Yeah. Yeah. That that tracks. Yeah. Yeah. And I like it because it does feel a little bit more Versus Cody in terms of you do get More of those preset things. You could do image previews in it.

Topic 8 17:56

Discussion of LunarVim Neovim distribution

Guest 3

Yeah.

Guest 3

Yeah. There there's a lot of feature, but I I Still have kind of a hard time really converting myself mostly because, I I wonder how like, what you would think about this. So One thing that I've always felt was off is that people often say that VIM is a lot faster, in terms of being able to have that muscle memory for keyboard shortcuts do things. But most of the time to do simple things like fuzzy find a file, I found it took, like, more keystrokes. So, like, for instance, with LunarVim, you would hit space bar to bring up the finder or the the the menu, f to bring up, like, the fuzzy finder and then start typing. We're in, like, Versus code, it's command p or whatever. Right? So you're often hitting space and then several other Keyboard commands. Is this just how it is, or or am I doing something wrong? Like, are you typically having to do 3 or 4,

Share