My Neovim configuration for Golang development in 2024 (Using lazy.nvim and go.nvim)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello my name is Mario welcome to another video in today's episode I'm sharing with you the Neo configuration I use for writing code in go in this video I won't show you all the plugins I use but rather the most important ones for go there is a link in the description of this video that points to the code the configuration that I have and also a blog post that you can use what I'm going to be doing right now is showing you the most popular ones which I think are the most valuable ones the structure I follow is the typical structure that use in Lua for neovim I'm using the lazy plugin I migrated from parer which is no longer maintain all of the plugins that I have to Lua and I try to find Lua specific plugins in this case I only have two of them but I still using Vim script the way is structure is the following there is an init Lua file that will load these two Lua files the default and lazy default includes configuration for viim you know show the line numbers show relative numbers use utf8 use the English as the default spelling language those kind of things nothing spectacular what is spectacular here will be what is under the plugins folder and this plugins folder is loaded by the lazy. Lua file everything down here is what is used when lazy is loaded the plugins I will show you are barber which is a teline plugin CMP which is a code completion plugin L line which which is status line plugin MIM 3 Seer which is to interacting with the language parer T cope which is for fif find and and interacting files and finally Navigator which is the one that in way uses all of the ones that I am showing you right here and provides a little bit more useful keymaps for interacting with go and other programming languages so let's start with the basics let me show you the different sections in neovim let's start by opening the go mode file this will be loading the language server protocol server that in this case is gopl that allows you to do code completion uh suggestion about different things about maybe ven ability checks maybe syntax errors those kind of things I'll show you those when we're talking about the CMP plugins in a moment what I want to show you first are the sections right here we have the tabl line using barbar down here we have the status line that it can show you the mode that you're in for example right now I'm in the insert mode the branch that I'm using which in this case will be main the file name which will be G mod on this side we have the file type we have as well as then coding and some indicators relative to where my cursor or my where I'm where I'm at in the context of the line and column you notice that if I move it on the right side you can see that is uh changing and of course all of these that I am um highlighting will be the section where you're coding you're showing you uh suggestions for code completion warnings and so on so forth I will show you more specific examples now so I show you the sections in Neo beim let's do something let's open the lazy configuration that I was talking about in the beginning of the video and how this works as you can see right here you will notice that this section will be used for loading lazy the first time and in downloading it and cloning it from the original repo and what I have here is actually loading the plugins that are under the Mario plugins folder let's open the one for barbar in this case we have it under barbar Lua there are different sections that are more or less the similar for all the plugins there is where you import the plugin itself you define some dependencies there is typically an init section and there is a big config section where you define key maps or other attributes that are applicable to the dependencies that you are loading in some cases you can also specify the version of the Plugin or some other attributes that are applicable to that plugin but for the most part are the sections that you will see one interesting thing to call out here will be the usage of this git science plugin this is used all over new and used by different plugins but I will show you how this looks like so let's go back to our go mode let's say I want to open a new file in this case don't worry about what I'm doing right here with in the case of this plugin that I'm show you the file browser I will describe that in a second what I want to show you is opening different files that we can use for demonstrating how Barb bar works so I have three tabs right the one here the one one here and the one right here so three different tabs that happen to have numbers as you can see there is one there is two and there is three down there and those numbers allow you to use the key maps to jump between them so let's say you use the option key or alt in PC you you can do option one alt one option two alt two or option three alt three to select those tabs if I want to go between them I can use Al comma to go left Al dot to go right and if I want to move let's say to move main to the second position I use alt shift comma to move to your left or alt shift dot to move to the right if I want to pin main make it the first one always available I press alt P if I want to pin it I press all p as well let's say I want to close it I want to press alt C and it will close that tab in particular if I want to close all of them except go mod will I go alt one and I press alt B and it will close all the tabs afterwards there are options as well so if I go and let's say I open internal errors one more time if you notice there is a x that you can use also if you want to use these to close it you press and use your mouse and also as well you can use again in opening errors again you can use your mouse to drag and drop between the two of them or how many tabs you have those are the configuration options that I have enabled there are more so please check out the with me for bar bar now let's talk about the status line plugin called laa Line This plugin is pretty much a straightforward I don't have too many options enable or configure but I want to call out a few things and you saw this already in a way there is a dependency for my theme called kuchin and there is this plugin called Dev icons and Dev icons uses a patch font that allows you to display the icons that you can see for example this Linux icon or this La icon as well as when I open a go file you will see the goer so this not only applies to this specific L line but it actually is useful when you're interacting with the file browser or maybe when doing fuzzy finding so again the configuration is pretty stressful let me show you a few interesting things about this in particular when we are editing a file in go again we're back into our go mode of the file as I told you before the status line displays the modes normal the branches the file name and the other things I show you in the beginning of this video so let's say I want to change the mode if I go into insert you will notice that now all the way down here it changed to a greenish kind of color if I go and go in a visual mode now it's kind of a purplish down here and similarly when I interact with if I go up and down down here you can see that it's moving so I close this and I go up and down up and down left and right you will see it changes depending on there's a percentage so I'm I'm scrolling down there's a percentage and what if I open let's say I open the rney well the icon changes as well and if I were using something that is not utf8 let's say asking it will display then coding as well here let's jump into the next plugin now we have the CMP plugins or the code completion plugins this is a little bit uh much more elaborated than the previous configurations I show you but it starts to get interesting because this is where we're combining the different plugins to give you a different look and feel and a different experience I want to call out a few things one will be this LSP kind MV plugin that uses the patch font that I show you before which is the dev uh Dev icons plugin that I showed you when we were doing the status line and also this one will be used for using a Snippets that I will show you as well for the configuration I have this indicator which is a tab that is used when there is some sort of like Auto completion enabl you can disable it because it sometimes it could be annoying so just get rid of this configuration if you don't feel like using it if you scroll down a little bit you will see configuration related to the mapping this is when you're scrolling down up and down with the code completion this is kind of the default configuration you just have to have it and finally we have this configuration for how the code completion of values that appear are displayed I like displaying the symbol and the text this means the name that represents the thing that you are already completing as well as a symbol to differentiate between some other things that may have a similar name so you can tell between a maybe a variable a function or a type or those kind of things so this is useful for me finally the last section is what I'm using for configuring the LSP servers that have different configuration options I'm using the default for go that is coming from the go. nbam plugin that I will show you soon but I also have the default configuration for python this is for Ruby and this is for PHP that I use every now and then mostly for go is using the default configuration that is coming from go. NVM and also enabled by Navigator so let me show you how this looks in practice so I'm back into our go mode file let me open a file that demonstrates this I'm going to open the too file that has a few different types defining here let me scroll down a little bit find something that we can use for so let's say I'm trying to find the options that are relative to the variable D that I have right here what will I do well typically you press D dot and you will see the different Auto apption options that you have now if you recall in the options that I was mentioning before there is a way to display the symbol and the text and this is where I was referring to is dis plain the symbol and the type in this case is a field this is a method this is a snippet if I do auto completion for the standard package or really any package that you have installed you can take that information as well so you can do a Hello World of course is a dumb example and you will notice that there are a few indicators that pop up from time to time and again this is relative to the Navigator plugin but let's say there is an action right here I can do space CA and what it's going to do is giveing me a menu to add an import for fum I import and save it and if I scroll up you will see that now it's indicated right here now because we're editing this file you will notice that there is also something else this line that you see there is a green line that indicates a new line was added this is coming from git signs and also down here there is another indicator that says we added three lines and the same way all the way up here so you have different ways to notice when a file is been modified and interacts with it different plugins that you have let's say I delete something let's say I delete this line now you can see that it was deleted up here down here and all the way up here let's say I change something let's I remove the indicator well now you will see it here you will see it here and you will see it all the way up there as well really nice right and let me show you the snippet I want to add the Snippets for task I want to add a new method so what I will do is scroll down a little bit press f m which is a snippit for a method which in this case we'll say okay T tab task tab method new of course this doesn't make any sense but you get idea tap t tap return nothing okay redundant this is a of course an example of using the fum to allow to add a new method let's go into the next plugin now it's time to talk about three CER three CER is a plug-in for interacting with the language parser 3 I'm using the basic configuration for this although it looks like it's a lot but really I'm just using the configuration for functions and classes which in this case will be the stru types so I want to call out a few things first of all we see here these text objects that allows you to work with objects which is the things that I was just saying now about the function um comments anything relative to the programming language anything syntactically that will apply you can do your typical Motions like the leading coping moving and so on so forth the other thing that I want to call out is this in three Seer context I probably you saw it if you were paying attention I will I will show you what exactly that looks like but more importantly if we scroll down a little bit you will see that I have a few things disabled like in this case there is a bug with the mark down implementation of uh three Seer is there's a buggy thing happening around now and then with relative to the context plugin so I disabled that one we have the ensured installed reer uh parsers which are the ones that I typically use these are installed automatically when you use lazy and finally another configuration to disable in the CSV highlight using three Seer because I'm using a different plugin for this as well now how does this look in practice let me show you again I'm back into go mode what I'm going to be doing is opening internal to do test to show you what context is I'm going to scroll down to line 31 you will see that I'm located right there and there is a line that shows up all the way right here that's the context and depending where you're located at it will give you more information about the depth that you have relative to the code that you're looking at let me show you a better example so if I scroll down more and more I go to line I go to 12 you will see right here that now it's calling out there is a for that you're in there there is another run method that it's being called this gets really interesting especially when you're having long functions like test but also gets interesting when you're dealing with different nested blocks of code next let me show you the Motions that you can use with the object plugin that I was mentioning a while ago for this what I'm going to be doing is I'm going to be going all the way down into the task type so you go 21 up to go to the task type and I'm going to show you a few different motions I want to select the whole task class what is called but it's really a stru as you know goes I do a visual around class and I will go and select all of that let's say I want to delete this class you will use the typical motion delete so delete around class it will go away similarly if I wanted to do something with the function validate I will do a delete around function and it will go away if I want to use select VF it will select it all right let's talk about the next plugins let's talk about the telescope plugins which are used for FY finding display lists and also have the extension for the file browser I personally like that a lot compared to the other ones that are available again you can use whatever you like the most in this case what I'm going to be showing you your typical call to the plugin that you're using as well as some of the dependencies and the one for file browser and some more configuration that I have down here I want to call out a few things this is a Lo on field that you have you can configure the displays that you have in different ways I like the way I'm going to show you better it works better for me but I also recommend you to look at the RH there are a few different examples that you can use and it's really highly configurable so you can change the colors and do a lot of things next we'll have the file browser configuration that again I like this the way it is but what I want to mention as well is the different key maps that I've been using for a while and this key maps are sort of what I'm used to so when I want to open the file browser I just press hyphen when I'm in normal mode all of these are in normal boat there is a key map for displaying files in the in the working directory displaying the three C symbols displaying options if there's a misspelled quot and whatnot let me show you how this works in practice one more time we are with our friend go dood and what I told you before I press hyphen it shows the file browser it gives you a preview on this right of the screen and if I just use you know my typical arrows I can go up and down but it also supports faly finding so you can do an in to show internal look can use i in it will go and choose I and from different files typical faly finding but let's say I want to go back to the pent folder I just press backspace or delete depending on if you're inpc or Mac I can do an internal enter I can do errors if I want to create a file delete a file move a file those are also options that you can do right here when using the file browser now let's talk about the key maps that I show you before so for that I'm using my leader key which will be comma FF and that will allow me to find files using a FY search let's say I'm looking for for errors okay there is an error there there's something that looks like error what what if I'm looking at CMD oh okay there are a bunch of CMD let's about the internal see the internal okay fine so you get an idea right is doing a fuz search relative to the workspace that you have in this case now let's consider something relative go specifically and could be any programming language but I want to give you an example in go if I do comma FX which will leader FX it shows you the three C symbols applicable to this errors. go file if this is really useful when you're trying to find something that you don't remember of and when we talk about the Navigator uh plugin this is extended even more but in this case I just want to give you this preview that is applicable to the default configuration when using three let's say you want to jump into something that says code okay there is a variable call code there is another um variable call code as well there is a field call code there's a method call code there's a error code type and again it's giving you kind of a preview of what's happening when you're selecting this is extremely useful when searching and interacting with your code let me show you the last one that I have configured in my key maps that would be a suggestion when we're trying to fix something that was misspelled let's say an order was written like this so it's missing the E of course right so what would you do typically you will call out your you know spelling dialogue and whatnot well there's an integration that allows you to do that so I press lader fs and it will show me know the spelling suggestions not well no of course it's an order and just replaces the word with what you have and what not all right let's talk about the last set of plugins that kind of consolidate everything and give you the experience that I like when I'm writing software in go so this is the Navigator plugin it uses most of the plugins I showed you before plus two of them that are written by the same author one of them will be this GUI Hua uh it's sort of like a model and an improvement of a model that you see in neovim as well as this LSP signature that allows you to display the signature of the method or function when you type it it basically displays the documentation and highlights the field that you are modifying other things that I have configured here are another key maps for go I want to call that out when I show you an example but here you will notice that I have a key map again most of them are these in normal mode so I have one for calling going PO for calling go build for calling go test for calling go test with coverage and these are the ones that I I like because I can jump between the test file and the original one just pressing a simple key map let me show you this in practice all right so we are with our friend go mod I want to show you what I think is really really helpful and this is a specific when you're working with large code bases there is a command called GW that allows you to search by symbol let's say you don't remember where exactly this symbol is defined let me see I'm looking for error so I'm looking error and it will display you all the errors okay there's an error response and error code let's say I'm looking for error code unknown I jump into error code unknown okay it looks like it's defined here it shows me a preview I go the file I select it and this is where it gets interesting because we can use the different commands that we have the different key rather and we can interact with the different tpes that we have okay we found our code unknown type we want to know who is using it we press gr and we get the reference for this type okay this is used by the internal errors right here there's one for Kafka there is more for rabbit mq and if you scroll down you can see also the preview and whatnot okay that's fine but I want to know where is this error code defined obviously it's right there right I mean this is pretty straightforward but if what if we didn't know where it was so you can use the GT key map and will jump into error code so this is where it is defined all right let's open a different file in this case will priority so in here I want to see what are the symbols in this document we can use g0 and it will show you the symbol remember the one that was show you everything in the workspace I in this case I'm only interested in priority. go in this file so I'll show you okay there's a priority string there's a priority field or rather constant uh a function method and so on so forth so again fuzzy search works as well and you can go and go in jump into this again these are navigation commands that are really useful when you're trying to look for specific things in your code base okay let's show you the plugin that describes documentation when you are hovering between the fields which is the LSP signature plugin that I was mentioning just now so if we are going here let's say I want to change error to nail you notice how orig error is highlighted okay let me change to internal dot you will notice that now the second one is highlighted so this is the whole point so when you go and modify things in methods or functions they will be highlighting those arguments and of course displaying the documentation as well so it's really helpful now as a reminder of of what you're modifying this is really important especially with those methods that happen to have the same types for different arguments now let me show you something specific to go which will be the key maps for building code coverage and whatnot so let's open again interal to-do in this case if I want to do a code coverage I will press contrl C which will run the tests and also more importantly the code coverage that you will see on the left side right here that's the code coverage if for whatever reason any of this was not covered it will show a red bar instead of the green one that we see right here if we want to build we can use the contrl b or built now let's open the Service task file now I'm interested about this task repository interface type I want to know who is using it for doing that I press GR it will give me the references of who is using this type but I want to know more than that I want to know hey who is implementing this task repository interface oh it seems like there's a type called task in mkd package one for post package and again preview you select it you can go and review the code and like I said before each one of these plugins has more configuration options you can configure it as much as you want but I want to keep this thing pragmatic I want to use the default values that are coming in the plugins as much as I can but in some cases I have to make a few changes because I'm used to a different workflow and whatnot so that's why I show you the options that I show you before please refer to the blog post there is also a document that I have in the blog post and I also includeed in the description of this video that goes specifically into the plugins and the key maps that I use and I have please refer to that one as well and with that that's it thank you for watching I hope you found this video useful I will talk to you next time take care stay safe see you
Info
Channel: Mario Carrion
Views: 4,267
Rating: undefined out of 5
Keywords: golang, go lang, golang tutorial, go lang tutorial, golang beginners, golang for beginners, learn golang, neovim tutorial, neovim golang, go.nvim, lazy.nvim, neovim 2024, golang 2024, golang vscode, golang goland, golang vim, golang vi
Id: n5_WLgxwkU8
Channel Id: undefined
Length: 23min 3sec (1383 seconds)
Published: Mon May 20 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.