The Vim Tutorial - Part One - Basic Commands

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Thank You!

👍︎︎ 3 👤︎︎ u/SurenGuide 📅︎︎ Dec 15 2018 🗫︎ replies
Captions
the text editor one of the most important programs on your computer this begs the question what is the best text editor out there I think the answer is obvious film of course let's get started [Music] so why vim why bother learning vim vim is this strange beast it's got this weird modal system to it it uses strange key bindings nothing makes sense as far as the keystrokes involved it's not like any other plain text editor you've ever used so why bother learning vim well for those of us that run unix-like operating systems such as Linux it makes a lot of sense VI or VM is installed on every unix-like operating system out there so you already have it on the system on minimal installs and server installs often vim is the only text editor installed on the system on minimal Linux distros for example I've installed you know many Linux distros where VM was the only text editor on the system and vim was the default text editor on the system even if there were other text editors installed so you go to edit a config file or something at the command-line and you end up in vim well wouldn't it be nice to be familiar with meum 2 to be able to do some basic editing of a file just to make your life easier if you're a Linux enthusiast a Linux guru you're doing any kind of daemon work you're a programmer what-have-you it makes a lot of sense to at least have some familiarity with me now why would you go beyond that why would you you know really dive into them and become a vm master it's because it's such a powerful tool if you live in the text editor it makes a lot of sense to really dive into them and learn the ins and outs because it is such a powerful tool you can fly around these text documents edit large chunks of text in them with far fewer keystrokes than you can with any other text editor so where do we begin learning them well there's a couple of different neat little programs you can run to help you learn the basics of them first I'll start with a fun one there is this web-based game called dumb adventures you can find it at film - adventures.com film adventures learning them while playing a game basically you navigate with the vim Keys hjkl you enter various film commands along the way to solve puzzles and beat the game so BIM Adventures is a nice little fun way to learn BIM but by far the most common way most of us get started learning BIM is the vim tutor so assuming vim is already installed on your system again those of us running Linux it should be there if for some reason it's not Debian and Ubuntu based system sudo apt install them get your vim here on an arch based system sudo pac-man - capitalists vim all right assuming film is already on your system though you have access to the film tutor so type all one word film tutor hit enter and you are now in vim this is a text document in BIM called the film tutor it is basically an instruction manual for vim so if I arrow down here to get to the first lesson moving the cursor went a little too far I'm going to arrow back up now the arrow keys you will never use the arrow keys on your keyboard in vim that is a no-no in fact when you're first learning vim for a lot of people it's a good idea to completely disable the arrow keys on your keyboard to break that habit because we're never gonna date with the arrow keys again the very first lesson lesson 1.1 moving the cursor hjkl hjkl are now your arrow keys so okay to move up ill to move right h to move left mange to move down k back up etc etc so this is how we navigate in vim from here on out mom why well because your your hands of course hjkl are kind of both on the home row but not really they're actually shifted one key over from where your hands naturally rest on the home road your hands naturally rest on the keyboard on JKL semicolon so why is it shifted over in vim hjkl being the arrow keys basically well because when this was created the creator of developed this decades ago and the kind of computers that he developed them to run on were like these old-school terminals they didn't have arrow keys they didn't have all these extra keys the arrow keys and the page up and page down they certainly didn't have the numeric keypad and all that as you can see hjkl on his keyboard served a double function they also served as the arrow keys this is why when he developed film hjkl he also developed in BIM to also serve as the arrow keys because that was what he was already used to so this is what we are stuck with today so I strongly suggest that you go through the vim tutor it takes about half an hour to go through the entire vim tutor it is a really nice way to quickly get up to speed with them you're probably gonna go through the vim tutor many times to really familiarize yourself with the ins and outs of them I'm not gonna use the vim tutor today I'm actually gonna exit out of the vim tutor because I'm not gonna go exactly in the film tutor or order of the lessons that it teaches so I don't want to to use the vim tutor on screen here I'm gonna open up some random text document on my system to do my tutorial so how do I exit out of the vim tutor how do I exit out of a film document there is a funny joke that you know often times users mistakenly launch film and can't figure out how to equip them well there are a million different ways to quit Billman oddly enough but none of them are very intuitive the most common way to quit a vim document is to type colon what does colon do it enters you into what is a called a command line mode we can now type a command such as the word quit colon quit will actually quit Jim you don't have to type the full word quit though : Q should work just fine and we are out of them so before I move on I do want to discuss a few more ways to quit vim so I'm gonna just quickly go back to the vim tutor for a second so I just told you how to quit vim is : Q to quit now what if I wanted to quit a document without saving changes to the file and so : q exclamation point quits without saving the document what if I want to write changes to the document before quitting : w for right Q to quit so write and then quit see how this works : exit also exits vim shorthand for exit would also be : X now you can also exit them without even doing any of the command line mode so no more entering : and then a word in normal mode and boom this also works to capital Z's so shift hold shift type ZZ also all of those exit them some of them write the file before quitting some of them quit without writing the foul so for purposes of this tutorial I'm just gonna open up a text file on my system to play around with and demonstrate some basic film commands so I'm gonna open up my cue tile config file so I use the cue tile tiling window manager I'm gonna open up the config file for this I'm gonna zoom in a little bit so you guys can see exactly what I'm doing now my film is gonna look a little differently than your VM by default film does not have the line numbers on the side here it's very easy to add that yet edit your film or C file to add the line numbers I'm gonna go over that in a later video also you're not gonna have the power line status bar at the bottom like I do so you will have some status stuff at the bottom but it will not be in this fancy power line layout the way I have it but that is just superfluous stuff it really doesn't matter for purposes of this tutorial everything I discuss all the commands are gonna work in your VM the same as my VM first things first film is a modal text editor what does that mean modal it means it has modes vim has several modes the first mode you need to know about is normal mode you guys see at the bottom and my status bar the word normal here you won't have the status bar but you will also see the word normal at the bottom of your vim that means we are in normal mode why is it normal mode because that is the mode you should be in most of the time that is why it's called normal mode now what does normal mode do well you can navigate with hjkl you notice the hjkl now navigate they don't actually type anything right I'm not adding hjkl and you know the actual text characters to the document this just lets me navigate there's other commands I could do to delete and copy and paste and move around the system or the text document this is normal mode so by the way that command I just typed there GG to G's in a row gets me to the top of the document GG will always get me to the top of the document shift G one time will get me to the last line of the document GG gets me to the first line of the document so there's the very first thing to learn now this was in normal mode what if I wanted to actually type a line of text then I have to get out of normal mode I have to type I on the keyboard that gets me to insert mode see how that makes sense I for insert mode now I can actually type something I could type this is a new line period and a hit enter so I just added a new line how do I get out of insert mode you hit escape on the keyboard there is a slight delay but you know like a one-second delay you hit escape and wait about one second and then it switches to normal mode why is there that slight delay there's reasons for that slight delay I won't get into but just know that when you switch from insert mode to normal mode with escape there is a slight delay if you if that slight delay bothers you so I'm gonna go back to insert mode with the I that slight delay bothers you just hit escape twice really quickly and you're back in normal mode just like that so I four insert escape twice get you to normal mode or just escape once if you don't mind waiting a second a lot of people hate the fact that to change from normal mode to an insert mode and BEC involves the escape key because you know your hands are on the home row and that Escape key you know that that's kind of a far stretch if you having to use the Escape key all the time so what a lot of people like to do is remap that Escape key to some other key on the keyboard a popular choice is the caps lock key because who uses the caps lock key anyway and the caps lock key is right on the homeroom so the caps lock key is a popular choice what I've done is I simply use two eyes to get back to normal mode so I per insert and then two eyes in a row gets me back to normal normal mode why did I choose two eyes is because there are very very few words in the English language that in that have two eyes consecutive consecutively in them so it's not likely that you're gonna type two eyes by accident very often so one eye for insert two eyes to get back to normal mode is what I do but by default I for insert escape and then wait a second to get back to normal mode there is a third mode we should discuss Vee it's you to visual mode what does visual mode do well you're able to select blocks of text now so if I type J to go down you see I'm selecting blocks of text now and this is very very powerful for quickly copying deleting moving large chunks of tech how to get out of visual mode the same way you got out of insert mode hit escape you have to wait for the delay once they can delay or just quickly escape twice without the delay so let's play around in this text document a little bit let's navigate around so hjkl moves us around in the document so if I type ill to move to the right I'm gonna go to the end of this line I want to go back to the very first character in this line how do I do that well to get back to the first character on the line you're on all you need to do is type 0 on the keyboard 0 takes you back to the first character of that line now if I want to navigate down the document a little bit we've already discussed this I want to get back to the very first line of the document again Jiji first line of the document shift G takes me to the last line of the document gg back to the top very simple we can also use G to move around to a specific line other than G G to get to the first line and shift G to get to the last line we could also do something like to shift G so to capital G gets me to the second line you see now my cursor went from the first line to the second line or what if I wanted to move to line 31 right here thirty-one capital G now I'm on the first character of the 31st line very quickly navigating around again without having to play with the mouse or really without even having to mess with the hjkl keys the hjkl keys you really even though they navigate for you and they move you around you're not gonna use them very often once you learn the more powerful functions in film so I'm gonna go back to the very first line here so I'm in normal mode so what if I wanted to delete something well X is what you use to delete characters so you see that my cursor is on the T I'm in normal mode if I type X on the keyboard T is deleted by type X one more time the H is deleted and so forth and so on how do I undo exactly what I just did you on the keyboard you undo makes a lot of sense right to you gets me back the s u gets me back the ID the H and the T so X to delete what you the character under the cursor you always undo or ya undoes is that a word undoes it undos not sure anyway you to undo what you just did so what if I wanted to delete something more than just one character at a time well you could - X to delete two characters see th both were deleted undo what 3x would delete thi and that word undo so yeah that works if I wanted to delete a whole word though what do you think the key combination for delete word nvm is you guessed it D for delete w forward you see how that works delete word DW again that words gone DW again that words gone I'm gonna undo a couple of times to get back I keep on doing it'll finally tell me I'm already at the oldest change which the oldest change eliminates the line I was playing around in well that's fine I'm gonna go to a different line anyway to play around in how about let's go to the fifth line so five capital G and I'm on the fifth line let's play around with this line so we learned how to do delete single characters delete words what if I wanted to delete a line DD is the most common way to delete a line to DS in a row DD DD DD let me undo get all those lines back alright so let's discuss navigating around a little more without the use of hjkl because that only moves us one character at a time right we can move around one word at a time how do we do that the W key on the keyboard of course for word type W it goes to the beginning character of each word keeps going forward see how that works if I wanted to go forward by word except the last character of a through every word we type e for the end of the word so he's going to keep going forward to the each word but it's always going to be on the last character of each word so W forward II for end of word moving by word single words is also kind of slow we could you know move forward how about three words and it'll take me three words forward that works or 20 words for her we can really jump around in the document you want to move backwards be on the keyboard takes you to the first character of the preceding work it basically is the opposite of W W moves forward to the next word B moves backwards to the previous word and as always we can add numbers to any of these commands to do multiples so if I want to move backwards three times three B to move backwards three words move forward five words if I want to delete Jen lines I could ten D D right I just deleted ten lines I need to undo that I can undo but I could also undo everything I've done ever in this document how about five undos that gets me all the way back to the very beginning where the document is exactly how we started heck I could even add those number keys to the hjkl so if I wanted to move lift iris to me right with the L key instead of just doing it a single character at a time I could do 10 hell and it would move me over 10 characters or 10 J to move down 10 characters etc etc so let's discuss the put command which is p on the keyboard for put so i'm going to go back to the top of the document Jiji gets me well I didn't have focus on the window here Gigi gets me at the top of the document here what if I wanted to delete that very first line dd deletes it now what if I want to place that line somewhere else well how about this empty space right here on line 17 that's where I wanna put that that line that I just deleted well first of all I'm gonna shift actually not shift I'm gonna 17 shift G so 17 capital G gets me to line 17 and then I type p on the keyboard and you see it puts that text actually it put it online I 18 it puts it on the line after I wanted it out online 17 I would have to enter insert mode I and then backspace and now I'm on line 17 to get out of insert mode again escape wait a second and then we're back in normal mode as always you know with these commands I could have added numbers both to the delete command and the put command if I wanted to copy and paste a large chunks of text so I'm gonna undo a few times to get back to where I was what if I did 10 DB delete 10 lines then I'm going to go to I don't know line 10 oh 10 capital G and then do a put you see it put those 10 lines that we deleted starting on line 11 and pasted them right there Oh P for the put command so I'm gonna undo everything I did I'm back at the top top of the document I'm going to type I to go into insert mode I'm going to type a line of text about this is a line of text and escape to get back into normal mode uh I mistyped something I typed this is a loan of text that doesn't make any sense uh let's change that let's discuss our which is the replace function here in VM so if I go over to o which needs to be I to replace Oh with I I type r4 replace and then the letter I see how that works the last command I want to discuss on part 1 of the VM tutorial is the change command the change command you need to type C on the keyboard or change so change equals C make sense right so I have this very first line this is a line of text what if I wanted to change that to that is a line of text well I would type C for change efore end of word and this is gone right it basically deleted this to the end of the word and it automatically puts me into insert mode I didn't have to type I to get into insert mode the change command automatically puts you in insert mode that way you can quickly take that right and then escape to get back to normal mode so I want to get back to the top of the document here that is a line of text what if I wanted to go back to this as a line of text again see II for change to the end of the word it automatically puts me into insert mode type dis escape back into normal mode again if I wanted to change more than just one word what if I wanted to change an entire line of text C for change and then dollar symbol for the entire line it deletes the entire line and places me into insert mode so I can write the new line this is the new line exclamation point it escaped to get back to normal mode so that concludes this part 1 of the film tutorial I hope you guys enjoyed this before I go I do have to tell you guys about some special people this show this show was made possible by Anson Carlos Chris David Lee or Rob and Tony they are the producers of the show they are my highest tiered patrons all over on patreon this show is also brought to you by all those fine ladies and gentlemen you see all those names on the screen they are the supporters of this channel without them none of this would be possible if you enjoyed this video please consider supporting distro tube over on patreon peace guys [Music]
Info
Channel: DistroTube
Views: 214,192
Rating: undefined out of 5
Keywords: vim, vimtutor, hjkl, Linux, text, editor, delete, commands, modes, normal, insert, visual, vim text editor, vim tutorial, vim tutorial for beginners, beginner vim, vim commands, learning vim, vim editor, vim basics, how to quit vim, vi editor, learn vim, learn vim editor, learn vim tutorial
Id: ER5JYFKkYDg
Channel Id: undefined
Length: 23min 59sec (1439 seconds)
Published: Tue Dec 11 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.