Learn How to Use the Vim Text Editor (Episode 1) - Basic Usage (and how to exit Vim)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] [Music] hello again everyone and welcome back to learn Linux TV and also welcome to my brand new Vim Series in this series I'm going to teach all you Vim beginners how to use vim and by the end of this series you'll know everything that you'll need to know to use Vim on a daily basis now I already had a Vim series on my channel but it was quite old and it was time for a refresh so this time around what I'm going to do is give you the same series again but it's going to be updated and modernized so if you've already seen that series or if you already know how to use Vim there's nothing new for you to learn in this series this series is for those of you that are starting out for the very first time however if you have seen my previous Series this one could serve as a refresher if you need one now I'm itching to dive into vim and start teaching it to you but there's one thing that I want to mention first before we get started Bim is one of those things that could be very complicated to learn not because it's complicated to learn but because there's just so much to it that a lot of people feel overwhelmed often someone might feel like they need to memorize everything about vim and that's almost impossible now don't get me wrong I'm sure there's somebody out there that has the entirety of Vim memorized I know I don't but I want to make sure that everyone understands that you don't need to memorize everything about Vim you only need to memorize the things that are related to your particular use case in this series I'm going to focus on the bare minimums the things that you have to know in order to use Vim so I'm not going to go over every single feature I'm going to go over every required feature and also some additional things as well to make your life easier quality of life tricks and things like that so you'll definitely learn a lot but I don't want anyone out there to feel like they have to learn everything because that's just a lot of pressure so if you focus on the things you need to know to get through your day-to-day use case for Vim then you should be just fine and by using Vim as your editor along the way you'll learn things as you go so you don't have to be in a rush or anything like that just take your time and have some fun now I'm itching to get started with them so let's dive in and do exactly that first of all in order to get started with BM you first need to have it installed so let's talk about that first what I'll do in this section is talk about how to gain access to Vim on Windows Mac OS as well as Linux and we'll start with Linux on some distributions you might have Vim installed already so the first thing we're going to do is try to determine if Vim is already available on our system and to do that what we could do is run command-v and then Vim just like that if we do receive output that means that Vim is installed if we don't well we have to install it in my case Vim is not installed so on my end I do need to install Vim I don't have it installed already and how you go about doing that when it comes to Linux depends on which distribution of Linux you happen to be running if for some reason you're not aware of which distribution you're running currently there's an easy way to find out what we could do is cut out the contents of a specific file and the file that we want to check the contents of is/ etsy slos hyen release just like that now on my end I'm running Debian 12 as you can see if you're running a derivative of Debian or possibly Ubuntu which is also a derivative of Debian or anything with the APT package manager I'm going to give you a command right now that'll get Vim installed on your system and again this is only for distributions that have access to the APT package manager so what we're going to do on Debian right here is we're going to run pseudo apt update and that'll refresh the package repository index and we're going to ignore those warnings right there but what I'm going to do now is install Vim here on Debian to do that I'll run sudu appt install and then we type the name of the package that we want to install and the one that I recommend is vim hyen Knox and that's the version of Vim that I'm going to be installing now there's multiple versions of Vim that we can run and this is just one of many but I chose this one because it's a personal favorite but it doesn't really matter you just need Vim on your system and you could get it from whatever Source you want in this case I'm just going to install this particular package but one thing to keep in mind is that regardless of which one you go with it won't make any difference when it comes to this series so I'll press enter to accept the default of yes and now Vim should be installed here on my Debian system to verify that I'll run command-v and then Vim again and this time I see output so now I know that Vim is in fact available here on my system now if you're not running Debian for example if you're running something like Fedora or Cent TOS or some sort of derivative of Enterprise Linux then the command for you might look something like this you might run sudu dnf install and then Vim hyphen enhanced and that's the version of Vim that I recommend on systems with the dnf package manager I'm not going to run that though because I don't have dnf on the system I've already installed Vim but if you're running a derivative of Centos or something with the dnf package manager then this Command right here should get you up and running with them now for those of you that are not running Linux maybe you're running something like Mac OS for those of you that are Mac users you'll have Vim installed automatically by default as it comes pre-installed with Mac OS so if you open up a terminal on your Mac you should have no problem opening Vim so that means if you're a Mac User there's nothing you have to do you have what you need and you're good to go another version of Vim that I want to point your attention to is neovim neovim is gaining quite a bit of popularity these days and it's available for most major operating systems and that includes Windows as well if that's what you happen to be running and for those of you that are running Windows as your local operating system then neovim is a great way to get started you can install neovim on any operating system like I mentioned but for those of you that are running Windows it's probably one of if not the best ways of getting Vim on your system of course you can run something like Windows services for Linux and install Vim that way but I recommend neovim because well again it's available for just about everything and windows users should have no problem obtaining neovim on their system now going back to you Mac users one more time another Contender that you might want to consider is Mac fim and what's cool about Mac fim is that it gives you a guey window that you can use to run Vim so that way it could be your guey text editor as well if you're interested in running Mac Vim then I'll leave a link to the official website for that particular project down in the description below so check that out if you're interested so at this point you might be wondering why are there so many versions of Vim which one should I go with is one better than another is there a tried andrue Vim release that I should be using among all of the ones that I mentioned well the thing is it doesn't matter which one you go with because your experience within this course will be the exact same either way the thing is I'm going over the basics in this course so we're not going to get into any of the situations where it might matter which one you choose for the most part it doesn't matter so just go along with whichever one you want to I don't care if it's Mac Vim or neovim or Vim enhanced or any of the others just make sure you have VM installed and you should be good to go now that we have Vim installed how do we go about using it well the easiest method is to type Vim inside your terminal and that'll open up the editor as you see right here if you want to exit Vim then you could type colon and notice at the bottom that it wants me to type something so I can exit by typing colon and then typing Q for quit and when I press enter I'm back to the command line so now we know how to open vim and we know how to exit Vim and believe it or not there's popular memes where people will make fun of Vim talking about how hard it is to exit vim and maybe they'll say something like I've been using Vim for years because I can't figure out how to exit it now this meme hasn't ever made sense to me because it's simply colon Q to exit vim and that's it it's not complicated at all but anyway we know how to open vim and we know how to exit Vim if you already know the name of the file or the path and the file name to a file that you want to edit you could also open that file straight away within Vim instead of opening it with an empty window and then opening the file later you can start Vim with whichever file you want to start editing now here in my home directory I have a few files here I have two config files and these are the files I'll be using as examples within this video but what I could do is open one of these up so I'll type vim and since I'm in the directory where the sm. andf file is stored all I should have to do is type out the file name of that file and then when I press enter it opens up the file as you can see right here so now we know two different ways of opening them as you just saw we could type Vim by itself to open a blank window or we could type Vim along with a file name or the file isn't in our local directory the path to the file and the file name along with vim and that'll open up the file like you see right here however let's take a closer look at what exactly is going on here when we open Vim this my sound confusing at first but just bear with me this will make sense very soon it's just one of those things that differentiates Vim from other text editors out there the fact that it has multiple modes and that's what we're going to take a look at right now 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. learnlinux.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 so what I'll do is type colon and then q and again that's going to allow me to Exit vim and now I'm back here at my terminal so I mentioned that Vim operates in multiple modes so so let's look at the first mode right now anytime we open vim and it doesn't matter if we open Vim by itself or with a file name every time we open Vim we start out in normal mode again this is going to make a lot more sense later on but just keep in mind for now that you always start in normal mode you might notice that you can't really type much of anything in this mode for example I'm pressing h on my keyboard you'll just have to take my word for it but as I type nothing is showing up up here on the screen at all and now I'm pressing e well nothing's happening so the first thing to know about normal mode is that this is not the mode that you'll be in when you are trying to actually edit a file so when you want to type something you'll need to be in a different mode and the mode that you'll need to be in is called insert mode if you press I on your keyboard you'll notice at the bottom left corner of the terminal window here we have the word insert and that's our indicator that we are currently using insert mode in this mode I can actually start typing so I'm able to type a sentence and just like with any other editor I could press enter and then I could create another sentence and so on and also like any other editor when I'm in insert mode I can also use the up down left and right arrows on my keyboard to move around and as you can see the cursor is responding anytime I press an arrow key again just like with any other editor so insert mode is where you're going to be spending the majority of your time because that's where you actually do your typing now this might be confusing but again just bear with me the takeaway for now is that if you want to do any type of actual typing then you'll do so in insert mode when you're finished typing you can press escape on your keyboard like I just did and notice that insert went away and now I'm back in normal mode again now let's just go through this one more time just to make sure that we have a proper handle on this so what I'll do is type colon and then I'll type Q for quit but it's not letting me well something else I wanted to show you is that if you want to quit without saving changes what you'll do is type colon and then Q like normal but then you'll add an exclamation mark that tells Vim that you want to exit no matter what you don't care if changes need to be Sav or not you just want to close out a Vim now before I press enter here though I do want to to mention that this is yet another mode this is command mode if I press Escape I'm back to normal mode and then colon that gets me into command mode so when I type Q I am executing a command I'm in command mode and if I want to exit without saving changes then I'll add the exclamation mark like you see here and now I'm back to the command line so again one more time just to make sure that we understand the different modes of Vim if we open Vim we're going to always start in normal mode if we press I on the keyboard that gets us into insert mode which is where we could do the majority of our typing when we're finished we can press escape to go back to normal mode and then command mode is accessed by typing colon from normal mode so I'll quit out of here and let's open up a file so again I have these two files right here so what I'll do is type vim and even though it's in my home directory I'm going to type the entire path here just to illustrate that you can do that as long as you have access to the file you should be able to open it from within vim and here we have the sample file and this is a Samba configuration file something that I used in another video I think a couple of years ago or so but I figured this would be a good example it's a config file but it doesn't really matter what file you open we just need a file to work with now what I'm going to do is show you how to save changes and first we'll need to make some sort of change to this file and one way that we could do that is just by adding something here so what I'll do is press I for insert mode and then I Arrow it over to the right and let's say that I'm setting up file server 2 I want to use the same config file but I want to change the name of the server here in the server string field for example and since I'm done making changes I could press escape and that gets me back to normal mode and now I'm ready to save the file and to save the file what we'll do is switch to command mode and we could type W for right that's going to save the file and we see at the bottom left there it tells us that the file has been written and now that we've saved changes what we could do is go back to command mode by typing colon cue for quit just like last time and then enter and we're back to the command line now there's another variation of saving the file that I want to show you that's a little bit quicker so if I recall the previous command again and go back into that file with Vim one more time what I want to show you is that you could save the file and exit in one command you don't have to go to command mode twice what you can do instead is type colon and then W for right just like last time and then Q for quit to write and then quit so you can stack the commands together like you see right here instead of entering them individually so when I press enter what's going to happen is this file is going to be saved I didn't even make any changes but if I did the changes would be saved but I'll press enter and that saved the file and it quit Vim at the same time now now before I close out the video there's a few more things that I want to show you guys so what I'll do is reopen that file yet again and that gets me back into vim and just like always I started in normal mode and just like I mentioned earlier we can enter insert mode by pressing I on our keyboard but there's more than one way that we could use to enter into insert mode you already know about I but did you know about capital A well if you hold down shift and press a Watch What Happens not only does it get us into insert mode but it also moves the cursor to the very end of the current line so if I wanted to append to the current line you know add some text after it then I could start insert mode with my cursor at the very end so for example if I wanted to add another line underneath this one right here I can simply press enter and I need a fewer key presses to get to that point now of course it's not going to save you a ton of time but it's definitely something that you should be aware of the fact that we have different ways we could use to get into insert mode mode that was capital A and again that gets us to the end of the line that's basically append mode we're going to append now we're in insert mode so aend isn't really its own mode but it talks about the fact that we can get the cursor to the very end of the line from the very beginning when we switch into insert mode now another trick I want to show you guys is how to undo so I made a change to this file right here and let's say that I don't want to save this particular file now the method for undoing goes like this we press escape to go back to normal mode and then on the keyboard we could press you for undo and that undoes the previous change if I press U again it'll undo the previous change before that but I'm already at the oldest change so there's really nothing for it to do I've already reverted the file back to its original state by removing the one change that I've made but if you had multiple changes in the file that you wanted to undo every time you press letter U on your keyboard from within normal mode it's going to undo do the most recent change and that's how you can undo within Vim now another trick within normal mode that I want to show you guys is that you can easily go to the beginning or the end of a line by pressing zero that gets us to the beginning of the line and by typing a dollar sign that gets us to the end of the line now remember typing capital A gets us into insert mode and puts a cursor at the end of the current line but typing a dollar sign on your keyboard that gets us to the end of the line as well but it does not switch us to insert mode just wanted to mention that in case that's something that you might find useful and there's our video I hope you enjoyed this first lesson in my brand new updated Vim series if you did enjoy this lesson be sure to click that like button to let YouTube know that you enjoyed this episode and whenever you're ready you can move on to the next episode but take your time learning is not a rush always focus on the fun of learning first and foremost that'll carry you through everything otherwise you might get burned out so just take your time go over the things that I've mentioned so far and when you're ready I'll see you in the next [Music] [Music] video [Music]
Info
Channel: Learn Linux TV
Views: 68,273
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: wACD8WEnImo
Channel Id: undefined
Length: 19min 33sec (1173 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.