Learn How to Use the Vim Text Editor (Episode 6) - Tips, Tricks and How to Configure Vim

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] [Music] hello again everyone and welcome back to the updated Vim series here on learn Linux TV here we are at the final episode because I feel like I've taught you just about everything you need to know in order to use Vim on a daily basis but there's a few more things that I think might be of value to you and those are the things that I'm going to cover in this episode what we're going to do in particular is take a look at the Vim config file we're going to add a configuration item to that file we're going to take a look at how to start on a particular line number basically a number of things that didn't fit in previous episodes we're going to tackle in this episode so how about you join me one last time to dive into the world of vim and we'll learn some really cool things so let's get started now the first thing that I'm going to show you how to to do is add line numbers this could be very useful if you are programming for example or even if you're not programming and you're just editing config files you might be interested in learning which line a specific config item is located on so line numbers are something that can be helpful for a lot of people so what I'm going to do is open an existing file we have a bunch of files here so I'll just open the updated file the one that I use to combine things together it's the largest file so I'll open that up and here we have a Vim window and nothing much is different yet but what we want to do is add line numbers so how exactly do we go about doing that well what we want to do is go into command mode and we could do that by typing colon just like that as you probably already know by now this is the last episode in the series so I hope you know that by now but anyway we're going to enter command mode and the command that we want to enter in right here is set and then number and watch what happens when we execute this command immediately we get line numbers in Vim how cool is that if I scroll down you can see all the line numbers on the left hand side of the screen but what if you want to take the line numbers away well one method is you can type colon again for command mode and then type set and then no number which is the opposite of number in this case and that makes the line numbers go away so using that trick you could toggle line numbers on or off anytime you'd like so I'll just add them back and there are the line numbers are again we see them on the left hand side of the screen so that could be very useful for config files and programming and things like that so if that's something that might be beneficial to you now you know how to go about adding line numbers however something interesting happens if I quit out of Vim again colon q and then I'll just go back into that file now notice when I go back into Vim the line numbers are now gone even though the line numbers were there when I closed Vim it it didn't remember my preference as soon as I opened it back up again then what happened is BM returned to its normal default of not having line numbers being shown here within the window so one thing you might be wondering is how to make changes persist and that's something that I'm going to show you how to do right now so what I'll do is close out a vim and I'll clear my screen and let's see what we could do to configure vim and make changes persist now there's a very special file that we can edit that'll will be a file that Vim will notice or pay attention to if it's present and if it is present with valid changes inside then that means those changes will take effect so in our home directory which is where I am right now we can create a file and the file will be called vmrc if you didn't already know a period in front of the file name will make it a hidden file something that I've gone over in other videos on this channel but the vmrc file if it's found within your home home directory what's going to happen is vim is going to notice it it's looking for it basically when Vim opens it's looking at your file system to find out if you do have a vmrc file and if it does find it it's going to attempt to load the values into memory assuming of course you don't have any typos or anything like that so what I'll do is press enter and we have an empty file right here so what I'm going to do is add the set number command that we've entered into command mode into itself and I'm going to include that right here but before I do I want to include a comment and in a vimrc file we could do that by typing a double quote just like that that's how we notate that the line is going to be a comment so I'll just add a little bit of information about what this particular change is going to do and then underneath that I'll type set and then number just like that and that's the same thing that I entered into command mode mode so what I'm going to do is save this file so colon WQ and then I'll recall the previous command I use to open up that file this one right here and watch what happens we have line numbers I didn't have to go in and activate line numbers line numbers were activated for me because I included that instruction right there in vim's config file by default you probably won't have a vmrc file in your home directory unless maybe your distribution just so happens to include one I don't think very many of them do but if that file is present then Vim is going to notice that like I mentioned and then load its config values into memory now back in that file the vmrc file we only have one instruction here we have set and then number that's the only thing that we're doing here but you can have additional things added to this config file as well every line is a comment or perhaps it's an instruction either way if this file exists it's going to be loaded into memory and you could add addition changes here and there's a number of changes and configs and tweaks and things that you can find online there's just a bunch of different things you could do to customize Vim but I'm not going to go into too much detail about that in this video but I at least wanted to show you where you go if you did want to make changes to vim's default configuration now another thing we can do when it comes to line numbers that I want to show you guys is you can open up themm and have it begin at a particular line number call the previous file so let's go back and open the previous file and at random I'm going to pick another line number so let's just randomly choose line number 20 I think that should be good enough let's go ahead and close out of this and I'll recall that command yet again and right here in between the file name and Vim itself I'm going to type A Plus symbol and then the line number the line that I want to start Vim at so if this works then the cursor should be begin on line number 20 so let's see if it does and it does as we can see the cursor is there on line number 20 so now you know you can begin your Vim session on a particular line and you could do that by typing Vim then you type plus along with a line number and that'll take you right to that line how cool is that now another thing that I mentioned in a previous video is that you can delete an entire line by pressing DD so for example I'll delete this line right here so I'll type D D and it's gone but what I didn't tell you is that when you do delete a line like that using DD it's going to copy that entire line into the paste buffers so if I add a new line here and then type P for put it's going to put that line right there where the cursor is and I can just keep doing that over and over again as you can see it's going to continually paste that line every time I type P on the keyboard but the thing is I didn't use VIs visual select like we did in a previous video instead all I did was use DD to delete the line and then after that all I have to do is type P on the keyboard to paste the line back in So if you didn't already know that DD deletes a line and also copies that line into your paste buffer well now you know now another thing that I went over in a previous video is the concept of buffers I also showed you how to switch between buffers with colon BP and BN or buffer previous and buffer next sorry to interrupt myself but I just wanted to let you know that I really enjoy making this content for you guys I have a ton of fun if you enjoy the content that I produce then please consider supporting learn Linux TV the thing is producing content like this isn't cheap so by giving back to the channel you can help me make even more content for you guys and to find out more about how you can support learn Linux TV what you could do is go to support. learn linux. TV and there you'll find some of the ways that you can help support the channel anyway let's get back to the video but how do you go about adding a buffer without switching to it I mean before what I showed you guys how to do is type colon to go into command mode and then e and then the file name and when I do that it takes me right to that file anyway let's delete that buffer with BD to go back to the original one and let's see how we can add a new buffer or create a new buffer with the contents of an existing file without switching to it immediately to do that in command mode what we'll do is we will type B add we want to add a buffer and we want to add a buffer with the text that's contained in the file that we just opened which was sb. andf so I'll press enter on that and it doesn't look like anything happened but I assure you something did happen I use buffer next to go to the next buffer there's the file so if you didn't already know that you can add a buffer to your existing Vim session without switching to it you now know that you could do that with the B add command in command mode along with the file name to do exactly that now the next thing that I'm going to show you actually the last thing that I'm going to show you before I close out this particular video is how you can activate splits from the very beginning of your Vim session as you recall we can open up vim and then we could type something like colon and then we could type split that splits the window as we already know but maybe we want to start themm with a few different files open you know from one command and have them both open in splits from the very beginning so what we'll do is pick a couple of files I'll pick the middle two there shares. CF and the SMB config file as well so what we'll do is type them just like before and then we'll give it the option- o and then we'll give it the first file name and then the second file name and Watch What Happens both files are open from the very beginning so if you are curious how to open Vim with a few different files open at the same time from one command well now you know how to do that we have both of these files open and we have them open in horizontal splits but I'm not quite done yet if we quit out of everything here and we start over and recall the previous Comm and watch what happens when I change the o to a capital O and believe it or not that one change makes a huge difference Watch What Happens it's the same thing but with a vertical split so now you know how to open two files in a vertical split and you could do that with the- capital O option along with- lowercase o if you wanted a horizontal split instead now there's going to be all kinds of additional tricks with Vim I mean Vim is a very complex editor I've only scratched the surface of it in this video but I definitely hope everything that I've taught you so far has been helpful and everything that I taught you so far should be everything that you need to know when it comes to using Vim on a regular basis and with that episode number six comes to a close but also this entire series comes to a close now this was just a beginner series I might do additional videos on Vim in the future in fact I'm sure I probably will so if you are sad that this you know series came to a close don't worry so much about that I'm always creating content for you guys around Linux and related Technologies so I'm sure I'll Circle back to them again in the future in the meantime though be sure to subscribe to learn Linux TV for the latest in Linux and thank you so much for checking out this series I really appreciate [Music] it [Music] [Music]
Info
Channel: Learn Linux TV
Views: 10,441
Rating: undefined out of 5
Keywords: Linux, gnu/linux, LearnLinuxTV, Learn Linux TV, LearnLinux.TV, Learn Linux, Linux Training, Linux Tutorials, Vim, Vim Tutorial, Programming Tools, Coding, Vim Editor, Linux Tutorial, Vim for Beginners, linux command line for beginners, linux operating system, linux for beginners 2023, vim editor, vim tutorial, vim commands, vim tutorial linux, vim config, vim tutorial for beginners, vim (software), vim text editor, vim tutorial playlist, learn vim, how to quit vim, text editor
Id: mW_YiBIJPo4
Channel Id: undefined
Length: 13min 15sec (795 seconds)
Published: Sat Oct 28 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.