Neovim for Elixir Devs: a guided tour of 10 plugins

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so I've made a list of 10 things that I think are important as an Elixir engineer when I'm using neovim number one envm LSP config Mason and Mason LSP config that's a mouthful but if you've done anything with neovim you're familiar with these this is how most people go about interacting with the native LSP system in neovim and Mason in particular is what most people use to download language servers secondly you're going to want some kind of autocomplete I use a combination of co-pilot via the C- pilot. Lua plugin and I use envm CMP a little bit next you're going to want some kind of formatter I personally use conform for this and then you're going to want some kind of linting system you can get by depending on the language server with just using native LSP for this but I like to have an extra plugin to do this and I'll show you why so I use env. lint for this then for syntax highlighting Elixir or syntax highlighting any language you'll probably going to want to use tree sitter but you could use Vim polyglot if you wanted next you're going to want some kind of fuzzy finder I personally use FCF but telescope is a great choice as well next you're going to want some way to run your xunit tests and for this I use Vim Das test but neot test is a great option too then you're going to want some kind of tab bar at least for me it's a necessity I need to see my buffers at the top of my window and you're also really going to want some kind of file manager I personally use Ranger for this and I have a specific plugin that I wrote myself for this but if I got started today I would probably use oil so I'm going to show you that and finally as an honorable mention because I personally don't use it myself is elixir tools this is a plugin that lets you use next LS a little bit easier which I'll go into in a little bit more detail but it's kind of an alternative language server for Elixir quick note from Andrew from the future if you would please consider hitting the Subscribe button I'm just getting started on my YouTube channel and I would really love to hit 100 subscribers that' be fantastic this is my first video on neovim I use neovim myself so I could talk about neovim for hours and maybe I will but if you like the video if it was useful to you at all um I would really appreciate the subscription you can always unsubscribe later if I disappoint you in some way so if you're already an eov user you can just add these plugins to your config you probably have half these plugins already if you're not a neovim user yet and you want to try it out and you want to write Elixir I would recommend going with this project here Kickstart envm it's really easy to download you can just clone it into your config en Vim directory you can back up your old one if you have any kind of config and just put this in its place and mess around with it and you can always change it back later if you want but I think this is the best starting point out there right now you can see most everything is in this init.lua file this is 99% of the config and then there's two little example folders here there's these two plugins that it kind of gives you as example uh off the bat and then there's a custom folder and I've put some of the plugins that I talked about in the intro here and we're going to talk about them but before we do that let's look at the init.lua file so if you clone envm Kickstart you're going to have something that looks a lot like this you're going to have this big block that configures a bunch of plugins and it does this with a plugin called lazy and you're going to have a bunch of these blocks that are config for various plugins and a lot of the stuff that was in that 1-10 list is already here we've already got LSP stuff we don't need to touch that we've already got autocomplete we don't really need to touch that as long as our language servers are running the an the autocomplete from envm CMP will pick up Elixir function signatures just fine so I'm going to jump around the list at random but starting with the tabs uh in neovim they're called buffers but we want to be able to see what files we have open basically you can do that really easily starting from the Kickstart by just adding this tabl line table and then within that add L line a as buffers and L line Z as tabs if I open a new file here let's open the read me in this directory this is what the buffers look like so up there in the upper left you can see now we have read me and we can go back to init.lua and we can move between them I'm moving between them with a key command that I will show you later on but just know that this is what is going to display our buffer list for us and then in the upper right we have tabs we only have one tab open right now so it just says one tabs and neovim are a little bit of a weird thing so if you're totally new to neovim just don't think about it right now now you're also going to have a section like this this servers list here I have added one line here that's just Elixir LS with an empty table you're going to want to do this and the default envm Kickstart config is going to try to install using Mason all the servers in this servers block so just by adding Elixir LS here when you restart neovim the next time it's going to install it right away all we need to do is add that that Elixir LS line and it will install Elixir LS successfully at least it does 99% of the time and you'll have autocomplete I I'll show that off in a little bit but the next thing you're going to need to do is set up syntax highlighting if you're going to use tree sitter Kickstart comes with a tree sitter config so you can just come here and we can add these two items here your list is going to look like this we're going to add Elixir and ex and these are going to be the two Tre Setter syntaxes for highlighting there's one final thing we need to do in this init.lua file and it's coming down to around line 273 your line number will be a little different and uncommenting this line right here this is going to load this file called custom plugins I'm going to show you in just a second so that file is here in Lua custom plugins and then go ahead and open this in knit. Lua and then then here you can add additional plugins that you want you can also add them in a knit. Lua but this is a Convention of the Kickstart so I'm going to follow it the first thing I recommend you set up is some kind of testing I like to be able to launch xunit tests directly from Vim I think it speeds up my workflow tremendously and I use this plugin called Vim test to do it I have it configured just a little bit I have this custom strategy which is basically a way to force it to open tests in a new buffer if you don't use this it opens them in like a split window which you may like you can go ahead and do that but if you want them to open in a new buffer you can copy this and then I have just a little bit of key bindings here when you use lazy. nbim which is the package manager you can configure key bindings directly in these package management blocks which is pretty nice so I have three key bindings here one to run the current file one to run the nearest test which will look at where your cursor is and run the nearest one and one to run the last test and I found that these three bindings do pretty much anything I ever need to do for running xunit tests next you're going to want some kind of file manager as I said before I use Ranger but oil is a really great option I have one key binding here bound to hyphen to just open oil so if I hit Hy you can see there's only one thing in this directory so we don't see anything else but we can hit hyphen again and now we're up to plugins so we can hit it again and now we see that custom and Kickstart are what's inside the Lua directory so if we hit hyphen again now we're up at the top of where we started with a knit. Lua so that's how you go up in this kind of method you just hit hyphen to go up and you hit enter on a directory to go down it may seem kind of weird at first and also if you want to reopen a file you can just hit enter on that file it may seem kind of strange at first but really try it out I think it's the best option today if you prefer some kind of tree system uh there's a plugin called envm tree or something like that that's a pretty good option I personally don't use tree navigation but you might like it now we come to linting and formatting which is probably the most difficult thing to set up language server stuff itself pretty much just works but autof formatting is a difficult problem it's not as simple as it looks I use a plugin specifically for formatting now depending on the language server you're using some of them run formatters Elixir language server does run form matters so you could get by with just that however when I'm working on Phoenix projects Elixir is not the only thing I need to deal with I need to write JavaScript or typescript I'm writing HTML I'm writing CSS I need to be able to run other formatters that aren't just the Phoenix or The Elixir format so I really recommend you try conform because it does make it really easy to set up these different formatters by file type it doesn't install them for you you still need to install them with Mason so be aware of that you're you are going to need to go to Mason and make sure that the formatters you want are installed or that they already exist on your in your executable directory this option is really important here this LSP fallback option this is what makes this whole system work with the native LSP formatting if you have a language server like elixir that defines its own formatter it's going to run the Elixir LS formatter when this conform stuff runs same with Lua here I think this is actually the language server but but basically the point of these blocks is that if these things are not found it's going to check the LSP fall back option and it is going to fall back to run the native formatter from the LSP the envm Kickstart repo does have this Auto format plugin that you might have seen you can use that instead but I think conform is a lot better now when it comes to linting running Credo is pretty much the only thing you really need to set up that's any difficult at all it's actually really easy to get started riding elixir with neovim as long as you have Elixir LS it all pretty much just works the one exception to to that is Credo you need some way to run Credo and there's basically two ways you can do it one is you could use Elixir tools which I will show off in a little bit or you can run some other kind of linting plugin there was one that was really popular for a long time called ale a lot of people do use that still but I use this envm lint it's really really great I love this plugin and it works a lot like conform you can Define linters by file type and I only have one set up here for Elixir and it's going to work as long as Credo is on your file system so that's all the plug-in stuff Kickstart gives you a lot out of the box we only needed to add a couple things but finally in this init.lua file back at the top of the directory I have some keymap suggestions for you you don't have to use these but this is my suggestion to you first off how have some way to switch buffers when you're looking at the tab bar so if I open oil and I load another file and then I open oil again and I load another file I want to be able to quickly go to the left so I have mapped that to contrl H to go left and contrl H again and go left again or contrl L to go right and these are of course uh Vim specific bindings H is always to the left and L is always to the right so CL and CH to me make a lot of sense for going right and left between buffers next this is a very minor tip uh it's not super relevant to Elixir and a lot of what I'm showing you isn't really but GF I recommend you remap G lowercase f to G uppercase F it's just more useful if you go to a file name in a buffer that has a little like coal in and then a line number after it if you hit g capital F it'll go to that line number so I think it's a more useful default again it's not Elixir specific stuff this is just quality of life stuff but I think you should try some of this out if you're getting started with neovim uh HL search I think is a musthave it lets you when you're searching you're going to see these highlights and then IM map escape to do no highlight that's what no is and then run the Escape key so when I hit Escape it's going to clear out the highlights and it's going to act as though I hit Escape anyway next capital J and capital K this is totally my opinion but I use this all the time I map these to do the up and down by paragraph motion that is normally on these brackets but I I have remapped it a little bit more to do this big nonsense here which you know I'm not a Vim script expert so I don't even know exactly how it works but it lets you maintain the jump list if you don't have something like this then when you go up and down by paragraph you're filling the jump list with new entries and it makes it basically impossible to use the jump list but if you map everything up like this then you can just kind of hold J and K to go up and down and that's how I navigate files in the omm a lot of people use plugins like leap that let you jump around to specific lines and stuff like that I am a very basic neovim user I guess I don't use anything like that I like to just hold down the key and go and that's just what I do but because I remap J you need some way to join lines capital J that is I've remapped capital J so you need some way to join lines and you can just hit colon and do J uh because that is a shortening of the join command so you can do colon join so that works but sometimes you need to join a lot of lines so I like to have g capital J to join a line and then my final mapping here is kind of weird I used to use Doom emac for a while I'm one of those people that have jumped around between emac and Vim uh a lot so I have muscle memory for closing a buffer with CX CK if you're an emac user then that would be familiar to you so I have BD for buffer delete bound to that uh if you're not an Emax user that this mapping is probably not going to be very useful for you so I would probably pick something else but suffice it to say you should have some kind of of mapping for deleting the current buffer and then final thing that's totally opinion I think scroll off 999 is so much nicer than not having the cursor centered all the time when you do this it just makes sure that there's always basically infinite uh space from the top and bottom so the cursor always stays in the center of the screen finally remember to come down here to this autoinstall thing and treesitter set that to true so all these are going to get installed when you start neovim the next time all right so I think that's about it for looking at the in. Lua let's open up an Elixir file and test out how some of this works so here we are in a project of mine this is an RSS app that I've been working on for forever so when you open a Elixir file or any file for the first time you're going to see lazy open you can open it yourself if you run the lazy command this is going to open automatically when you run neov the first time after and it's going to install all these plugins you can then close the window with zq you can also manually open the Mason menu by running the Mason command after opening a file it's going to have installed Elixir LS successfully so make sure that this has installed this is the key to doing most everything with developing Elixir you're going to want to make sure that this installed correctly if it didn't go back to your init.lua and make sure that you have that line where it says Elixir LS and just have a blank table but you can also install things manually here by going down to the specific entry and think you just hit enter on them and they install so close this with zq so now we're going to demonstrate first off that the language server is running we know that it's installed but we can also run LSP info and you can see it says there's one client attached to this buffer and it is the Elixir LS so we can close this with zq and we can test that it's running by for example let's change this variable to a variable that doesn't exist and then wait for the Diagnostics and here they go so we got one diagnostic telling us that this is an undefined variable and we have another one saying that we're not using con so that's the benefit first off of having Elixir LS running you're going to get Diagnostics that is the key reason that you're going to want to run it you also have access to autocomplete so if we start a new line and we type uh put whatever we're going to see a bunch of things that we can autocomplete so if we keep typing we're also going to see the signature of this function and this all comes from the envm CMP plugin but there's also some stuff that's configuring the signature head and it all comes from Kickstart that's why Kickstart is the best way to start with neovim in my opinion now this is easy to achieve it's easy to get autocomplete and Diagnostics working with Elixir The Credo thing is more difficult um but I can show you that Credo works if you follow the directions that we went over if you add a comment uh fix me whatever crto has a rule that looks for these and we know that this is a CREDO rule because if we come here and run mix Credo it's going to tell us that oh this is from Credo so that's 90% of it right there you need a way to run crto you need a way to get Diagnostics you need a way to get autocomplete and you also need formatting so if I do something that would be incorrect formatting like I indent this one too many and I hit save you can see it formats it and it's formatting it with the Elixir formatter from the language server but of course we set up conform so if we wanted to we could have different formatters going on and whatever but for Elixir all we need is the formatter from Elixir LS but if we were running a Javascript file in our Phoenix project it'd be able to format those with custom formatters too that's why I think this is the way to go and as for test running I opened a test here in this project let me show you that test nearest command so if we hit leader capital T and then n it's going to run a new buffer and it's going to run that test or we can hit capital t f and it's going to run all the tests in this this file so that's why I really like Vim test it's really easy to just come here to a specific test and just run that one test now what about fuzzy finding I kind of glossed over that there's nothing Elixir specific about it but Kickstart comes with telescope out of the box and if you're getting started that's a great option I use FCF myself but telescope is nice so you can see there's some fuzzy search options here if we hit leader slash we're going to get fuzzy search within this buffer or we can hit leader leader to get fuzzy search of the current buffers or we can hit leader s for search and then f for files and we can find a file in our project and this is probably the thing you're going to be doing the most I don't use Kickstart and I don't even use telescope for that matter so of course I have different key bindings for this but if you're getting started Kickstart is a good way to experiment with using a telescope for fuzzy finding so then we come to Elixir tools I think it's a fantastic plugin I just don't use it myself yet because I haven't been using next LS myself so basically the way it stands right now with language servers and elixir you've got Elixir LS which is I'm not sure if it's official I think it is offici IAL but I don't know if it's maintained by like The Elixir core team or not but Elixir LS is like the main formatter option you have and then this guy uh wrote this new language server called Next LS and you can read through this yourself it's got a whole bunch of different options and he made this plugin called Elixir tools and it lets you run next LS in addition to running Credo automatically so if you did that you wouldn't need envm lint and it can also run Elixir LS so you can run them both and it's got some commands to run mix tasks and Vim projectionist is a whole different thing and this is how you set it up here it's real easy to set up the only thing you need to do is if you have Elixir LS stuff in your LSP config you need to then remove it from there and configure it here in your Elixir tools block or you can set this to enable false and you can leave your LSP config alone and you can still configure elextra LS with your LSP config stuff and just enable next LS here definitely give it a shot um you know I might I might set it up right after this video I have no idea if I if it turns out I love it I'll make an update for you that's pretty much it that's how I write Elixir I write Elixir every day I don't have this exact config but this is a great way to get started or maybe you're already using neovim and you just want to see what a random Elixir engineer uses on a day-to-day basis my setup includes all these plugins plus some other stuff but if you're getting started I thought you might find this interesting
Info
Channel: Andrew Stewart | src_rip
Views: 2,792
Rating: undefined out of 5
Keywords: elixir, elixirlang, phoenix, vim, neovim
Id: o7PnaiwPHiY
Channel Id: undefined
Length: 25min 31sec (1531 seconds)
Published: Thu Jan 04 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.