Installing Telescope Plugin0:00
So far, we've been using the vim command to open files, but that's pretty slow, and it requires us to know the file structure of the project we're in. So let's make it better. Let's jump back into our plugins.lua file, and we'll use shift-g to jump all the way down to the bottom. And I'll paste in a config for the Telescope Fuzzy Finder plugin I'd like to use. Now this one is a little bit more complex, because it has a few more requirements. The first one here is the only hard requirement of Telescope, everything else is optional. This one will display file type icons beside our files, as long as we've got one of the nerd fonts that I mentioned in an earlier lesson.
This one will display file type icons beside our files, as long as we've got one of the nerd fonts that I mentioned in an earlier lesson. And these two are first-party extensions. This first one we'll go over a bit later, and this second one just improves the fuzzy finding performance. For our config function, at the moment, we're purely just calling the setup method to start everything up. So let's go ahead and save this file, and then we'll call packasync to download and install everything. And there we go.
Using Telescope Find Files1:02
install everything. And there we go. Now I think if we try and run Telescope, yeah, there's no Telescope command at the moment. So let's go ahead and we'll quit out of NeoVim, and then we'll open it back up again. And now we should be able to run Telescope. Now by default, this presents us with a list of all the different search sources that Telescope has. So if we come up, we can kind of see all the different things that Telescope will let us search. It'll show us all of our open buffers, different things in the search history, command history,
search. It'll show us all of our open buffers, different things in the search history, command history, all sorts of different stuff. But for our purposes, we want to use the find files searcher. And so once we select this, it presents us a list with all of our files, and we can use fuzzy searching to jump straight to the file we want, so in this case, plugins. Now obviously we don't want to have to choose our built-in each time, so you can also run Telescope and then just pass in, and you can use tab completion here, and pass in the name of the source we want to search in. So that'll jump us straight into that menu.
of the source we want to search in. So that'll jump us straight into that menu. Now this is already pretty handy, and I imagine you could figure out how you might go about adding some leader key aliases to open up Telescope. So now I want to show you how I configure Telescope, just to give you some inspiration of the different things you might want to do. So let's press escape to come out of here. You've got to press escape twice by default, once to go into normal mode of Telescope and then again to come out of it, and we'll be changing that shortly. So let's go ahead and pass some config options to setup.
Extracting Config to File2:26
then again to come out of it, and we'll be changing that shortly. So let's go ahead and pass some config options to setup. Now the config object that I want to use is going to be a little bit big, and I don't really want to put it inside this file. So let's talk about how we can extract some of our plugin configuration to separate files. So I'm going to go ahead and remove the setup method on the end here, so I just used F dot to jump to that dot, and then shift D to delete to the end of the line. And then let's change this require to user/plugins/telescope. And then we can go ahead and save that file, and let's go and create that file now. So we want to go nvim lua user plugins telescope.lua.
And then we can go ahead and save that file, and let's go and create that file now. So we want to go nvim lua/user/plugins/telescope.lua. Now this plugins directory does not exist yet, but that's okay because if you installed the vim-heritage plugin that I mentioned in a previous lesson, this directory will automatically be created for us when we save the file. So let's go ahead and open up this, and I'm going to paste in my config, and then we'll walk through it together. So first off, I'm just importing this actions function that we'll be using later. I then use a vim command to link some of the telescope highlight groups to some of the built-in groups, just so that it'll use some of the elements from the theme I'm using.
on that one as well. Then I'm enabling the two extensions that we installed. So the FCF one was a fuzzy finder improvement. This just improves the speed of telescope's fuzzy finder. And this live grep args one allows us to do more advanced searches of text inside files. I then set up quite a few different key maps. So I've got leader F is my main telescope key bind, and that calls the find files picker straight away. I then have leader shift F, and this one does find files, but it also includes things that have been git ignored.
I then have leader shift F, and this one does find files, but it also includes things that have been git ignored. I have leader B, which will show all my open buffers and allow me to quickly switch between them. I have leader G, which will do my live grep, so this is searching for text inside files. Leader H will do old files, which I'm calling history, so that shows my file history. And leader S will show me LSP document symbols, and we'll get to LSP stuff a little bit later on. So let's go ahead and save that file, and we'll come back to our main plugin file, and let's just make sure we've done a packer compile inside there.
So let's go ahead and save that file, and we'll come back to our main plugin file, and let's just make sure we've done a packer compile inside there. And let's just close NeoVim and open it up again. So now I should be able to do space F, and I've got a much better looking fuzzy finder. There's still a few little tweaks I want to make, but now the search is at the top. I've got nice little headings, a little search icon. I'm still not a fan of these white borders that are around these other two windows here, and the results window and the file preview window. So I'll quickly go and explain why that one is. Let's come back down into our telescope.lua file, and we'll jump up to these highlight.
Fixing Telescope Highlights6:41
So I'll quickly go and explain why that one is. Let's come back down into our telescope.lua file, and we'll jump up to these highlight links. So you might have remembered in a previous lesson we were using the normal float and float border for our packer floating windows. So using the highlight link command, I'm telling Vim that any time it's looking for the telescope prompt normal highlight group to just grab everything from the normal float highlight group instead. And similarly for the prompt border, I'm using the float border. And the prompt ones are these ones up here.
And similarly for the prompt border, I'm using the float border. And the prompt ones are these ones up here. So the prompt border is what's around the edges, and then the prompt normal is what's in the middle. The prompt title and preview title, I've just chosen one of the built-in highlights that I like the look of, and that's what makes these things blue, which is kind of nice. But these telescopeNormal and telescopeBorder highlight groups are the ones that are currently not quite the way that I want them. And it's mostly to do with this cursorLineBackground. So let's go back to our plugins.lua file, which we can now jump to with fuzzy finding,
Now the cursor line's not really intended to be used for this. The cursor line, just to show you, if I say set cursor line, that's this little background color that will follow our cursor around, which can make it easier to find where our cursor is on the screen. And the reason I like to use the cursor line highlight group is because typically this is a very, very subtle color. So in this case, it's a dark gray that's only slightly lighter than our background color. And so if we call packer compile on here, and then let's run telescope, let's see, what have I done?
And so if we call packer compile on here, and then let's run telescope, let's see, what have I done? Let me save that, and then run packer compile. There we go. So now you can see we're using this cursor line background around the edges of here. And to me, it kind of just gives this whole UI a nice layered kind of look. We've got our background here, which is darker. We've then got a slightly lighter color for here, and then the items that attract our most attention are in the most light color. Now I'm just going to turn off that cursor line, so we'll say set no cursor line, and
most attention are in the most light color. Now I'm just going to turn off that cursor line, so we'll say set noCursorLine, and then we're good to go. So let's jump back into the config for Telescope, and we'll come down to see some of these extra mappings. So leader shift F will search all files. Now in this particular project, I don't have anything git ignored, so it doesn't really search anything extra, but this is really handy if we want to search for files inside our vendor directory or our node_modules directory. leader B will show our open buffers, and we can easily switch between them.
Live Grep with Ripgrep9:23
our vendor directory or our node_modules directory. Leader B will show our open buffers, and we can easily switch between them. We can fuzzy search them, all that sort of good stuff. Leader G is the one I really want to talk about. So this one allows us to search for text inside files, and this picker requires us to have an extra program installed on our computer called ripgrep. So I'm going to open up a new window down here, and we'll just talk about ripgrep. So ripgrep creates a command called rg, and this is kind of like grep, but a lot faster. So I could search for say, ripgrep telescope, and that will find every occurrence of telescope in my project.
So I could search for say, ripgrep telescope, and that will find every occurrence of telescope in my project. And it doesn't seem to matter how big the project is, this thing is just so, so fast. So go ahead and make sure you have that installed on your operating system, and then if we come back over here and we do space G, I can also run that search inside here, and we can see all the matches of telescope in our file. We can also do some more advanced stuff. So if I was to press control K, I can now say -T lure to show me only files with the file type of lure, and maybe I also want to only show stuff that's in the nvim lure directory.
Adding Nvim-Tree Sidebar10:31
the file type of lure, and maybe I also want to only show stuff that's in the nvim lure directory. Alright, let's come back to our plugins file, and we'll come back to the bottom, and let's add one more plugin to help us find files, and that is a file tree sidebar. So I'm going to go ahead and paste this one in. This one's called nvim-tree, and this one also optionally requires the nvim-web-dev-icons package. I have this as a requirement for this one and telescope, just in case I ever remove one of them, it always makes sure that package is installed. Once again, our config function at the moment is just calling the setup method on the nvim.
one of them, it always makes sure that package is installed. Once again, our config function at the moment is just calling the setup method on the nvim-tree module. So let's go ahead and save this file, and we'll do our pack async, and that should install our nvim-tree. So let's go ahead and see if we can run that one, nvim-tree, excellent. So let's say nvim-tree open, and you'll see now we've got a little file browser on the side here that we can open up and navigate through all of our files. Once again, this one has heaps of customizations, so I'll quickly show you the customizations that I like to make.
Once again, this one has heaps of customizations, so I'll quickly show you the customizations that I like to make. So let's go over here, and we will get rid of our setup method, and let's change our require to user plugins nvim tree, we'll save that. And now let's come over into our plugins directory, and if I've got my cursor over here, I can press A to create a new file in here. So you'll see down the bottom it's filled out the directory that I was in. So here I could say nvim tree.lua, and that'll create that file, and then I can just press Enter on it to open that file. So let's go ahead and paste in this config here, and we'll go through a few of these
Enter on it to open that file. So let's go ahead and paste in this config here, and we'll go through a few of these options. So in this case, nvim-tree by default will ignore git ignored files, but I want to show them, so I disable that. I then turn on this group_empty function. So if you notice over on the side here, we've got this Lua directory, and the only thing in this directory is the user directory. So you'll see what happens once we enable that option. I then disable the folder arrow icons, so you'll notice here all these folders have
Now we can actually just source this file as it is, and let's just reopen nvim tree after we've done that. And now we see we've got our indent lines, and you can see our Lua user directory here. It's collapsed that into a single line because there's nothing else inside that Lua directory, so it doesn't bother showing an extra node for that one. Now let's also go ahead and create a key mapping. So in this case, we'll say vim.keymap.set, we want a normal mode key mapping for leader n. I like to use n for nvim tree, but you can make it anything you like. And we want this to open the nvim tree find file toggle command, and then we'll enter.
