< Return to Video

Lecture 3: Editors (vim) (2020)

  • 0:00 - 0:05
    Okay, cool. So, welcome to the third
  • 0:03 - 0:08
    lecture of the missing semester of your
  • 0:05 - 0:10
    si a second today we're going to be
  • 0:08 - 0:12
    talking about text editors this is a
  • 0:10 - 0:13
    topic that I really like I think it's
  • 0:12 - 0:15
    one of the most valuable topics that
  • 0:13 - 0:17
    we're teaching in this class because as
  • 0:15 - 0:20
    programmers you spend so much of your
  • 0:17 - 0:22
    time editing text editing programs that
  • 0:20 - 0:24
    if you invest time into making yourself
  • 0:22 - 0:26
    more efficient at doing this you'll save
  • 0:24 - 0:28
    a ton of time probably hundreds of hours
  • 0:26 - 0:32
    over the course of your undergrad or
  • 0:28 - 0:34
    over the course of your career so text
  • 0:32 - 0:36
    editors are a little bit different than
  • 0:34 - 0:38
    other programs you might use to edit say
  • 0:36 - 0:40
    things like English prose because
  • 0:38 - 0:42
    programming is different than writing
  • 0:40 - 0:44
    English prose when you're programming
  • 0:42 - 0:46
    you spend a lot of time reading what
  • 0:44 - 0:48
    you've written you spend a lot of time
  • 0:46 - 0:49
    navigating around a buffer and you spend
  • 0:48 - 0:51
    a lot of time making little edits to
  • 0:49 - 0:53
    code all over the place rather than just
  • 0:51 - 0:54
    writing in a long stream like you do
  • 0:53 - 0:55
    when you're writing an essay or
  • 0:54 - 0:56
    something and so it makes sense that
  • 0:55 - 0:58
    there different programs for these
  • 0:56 - 0:59
    different purposes right so yeah things
  • 0:58 - 1:01
    like Microsoft Word for writing essays
  • 0:59 - 1:06
    and things like vim and Emacs and vs
  • 1:01 - 1:07
    code and sublime for writing code so the
  • 1:06 - 1:09
    way you learn a text editor and become
  • 1:07 - 1:11
    really good at it is you start with a
  • 1:09 - 1:13
    tutorial and so that's basically going
  • 1:11 - 1:16
    to be the function of today's lecture
  • 1:13 - 1:18
    plus the exercises we've given you and
  • 1:16 - 1:20
    then after the tutorial you need to
  • 1:18 - 1:22
    stick with the editor for all your
  • 1:20 - 1:24
    editing tasks and when you're learning a
  • 1:22 - 1:25
    sophisticated tool so today we're going
  • 1:24 - 1:27
    to teach you vim which is one powerful
  • 1:25 - 1:28
    editor that a lot of programmers use
  • 1:27 - 1:30
    when you're learning such a
  • 1:28 - 1:32
    sophisticated tool it may be the case
  • 1:30 - 1:34
    that initially switching to this tool
  • 1:32 - 1:36
    slows you down a little bit when you're
  • 1:34 - 1:39
    programming but stick with it because
  • 1:36 - 1:41
    I'd say that in about 20 hours of
  • 1:39 - 1:43
    programming using a new editor you'll be
  • 1:41 - 1:45
    back to the same speed at which you
  • 1:43 - 1:46
    programmed using your old tool and then
  • 1:45 - 1:48
    after that the benefits will start and
  • 1:46 - 1:50
    you'll get faster and faster as you
  • 1:48 - 1:54
    learn more with these sophisticated
  • 1:50 - 1:55
    programs like them it takes not way too
  • 1:54 - 1:58
    long to learn the basics but a lifetime
  • 1:55 - 2:00
    to master and so throughout the time
  • 1:58 - 2:02
    you're using this tool make sure you
  • 2:00 - 2:03
    look things up as you go if you ever get
  • 2:02 - 2:05
    to a point where you're like oh this is
  • 2:03 - 2:06
    a really inefficient way of doing things
  • 2:05 - 2:10
    is there a better way the answer is
  • 2:06 - 2:12
    almost always yes because these text
  • 2:10 - 2:14
    editors were written by programmers for
  • 2:12 - 2:14
    programmers and so of course like the
  • 2:14 - 2:15
    peep
  • 2:14 - 2:17
    I wrote these tolls ran into the same
  • 2:15 - 2:18
    kinds of issues and fixed them so that
  • 2:17 - 2:20
    you don't need to deal with these
  • 2:18 - 2:22
    anymore and so yeah as you're learning
  • 2:20 - 2:24
    make sure you look things up as you go
  • 2:22 - 2:25
    either use Google or feel free to send
  • 2:24 - 2:27
    us emails if you have questions or come
  • 2:25 - 2:30
    to office hours and we'll help you
  • 2:27 - 2:32
    figure out how to do things really fast
  • 2:30 - 2:34
    so as far as which editor to learn in
  • 2:32 - 2:36
    previous iterations of this class we
  • 2:34 - 2:37
    actually avoided teaching a specific
  • 2:36 - 2:39
    editor because we didn't want to enforce
  • 2:37 - 2:40
    our opinions on you guys but we actually
  • 2:39 - 2:42
    think that it's really useful to teach
  • 2:40 - 2:45
    you how to use one particular tool and
  • 2:42 - 2:46
    use it well and so people have really
  • 2:45 - 2:48
    strong opinions about editor so you can
  • 2:46 - 2:52
    see the course notes for more links on
  • 2:48 - 2:54
    this topic looking at which editors have
  • 2:52 - 2:57
    been popular over the years Stack
  • 2:54 - 2:59
    Overflow I'm sure you've all heard of
  • 2:57 - 3:00
    that does a survey every year asking
  • 2:59 - 3:02
    developers various questions and one
  • 3:00 - 3:03
    thing to ask is which TextEdit Derk do
  • 3:02 - 3:05
    you use and it seems to be that
  • 3:03 - 3:08
    currently the most popular kind of
  • 3:05 - 3:10
    graphical editor is vs code and the most
  • 3:08 - 3:12
    popular editor that is based within a
  • 3:10 - 3:14
    command line interface is vim and so
  • 3:12 - 3:16
    we're going to be teaching you vim and
  • 3:14 - 3:18
    there a couple reasons for this one is
  • 3:16 - 3:20
    that all the instructors so me John and
  • 3:18 - 3:21
    Jose use vim as our primary editor and
  • 3:20 - 3:23
    we've been doing this for many years and
  • 3:21 - 3:25
    we've been very happy with it
  • 3:23 - 3:29
    and we think that there are a lot of
  • 3:25 - 3:30
    interesting ideas behind them so even if
  • 3:29 - 3:32
    you don't end up using this particular
  • 3:30 - 3:36
    tool in the long term I think it's
  • 3:32 - 3:37
    valuable to learn these ideas and also a
  • 3:36 - 3:39
    lot of tools have actually been really
  • 3:37 - 3:42
    excited about the ideas in vim and so
  • 3:39 - 3:44
    they support a vim emulation mode for
  • 3:42 - 3:46
    example vs code what's apparently the
  • 3:44 - 3:48
    most popular editor in use today
  • 3:46 - 3:51
    supports vim bindings and this vim
  • 3:48 - 3:54
    emulation mode as of now has like 1.4
  • 3:51 - 3:56
    million downloads and as you'll see over
  • 3:54 - 3:58
    the course of this lecture a lot of
  • 3:56 - 4:00
    different tools like including your
  • 3:58 - 4:02
    shell including things like the Python
  • 4:00 - 4:03
    repple and like Jupiter notebook and all
  • 4:02 - 4:05
    sorts of other things even your web
  • 4:03 - 4:07
    browser can support of emulation mode
  • 4:05 - 4:10
    and so yeah we're going to be teaching
  • 4:07 - 4:12
    you this really neat tool today and in
  • 4:10 - 4:14
    this lecture we can't really cover all
  • 4:12 - 4:17
    of them right it's a very powerful tool
  • 4:14 - 4:19
    but our goal is to teach you and the
  • 4:17 - 4:21
    core philosophy of them like the really
  • 4:19 - 4:22
    neat ideas behind it and then in
  • 4:21 - 4:24
    addition to that some of the basics like
  • 4:22 - 4:25
    how do you open a file close a file
  • 4:24 - 4:27
    navigate around a file make edits and
  • 4:25 - 4:29
    things like that and
  • 4:27 - 4:30
    you may not remember every single little
  • 4:29 - 4:31
    detail from this lecture because we're
  • 4:30 - 4:33
    gonna go pretty fast through some of the
  • 4:31 - 4:35
    material but it's all in the lecture
  • 4:33 - 4:37
    notes and then the exercises actually
  • 4:35 - 4:38
    give you links to some tutorials and
  • 4:37 - 4:40
    things so I highly recommend that you
  • 4:38 - 4:44
    actually go through all the exercises at
  • 4:40 - 4:49
    least the non advanced exercises any
  • 4:44 - 4:51
    questions so far great okay so one of
  • 4:49 - 4:54
    the really cool ideas behind them is
  • 4:51 - 4:56
    that vim is a modal editor what does
  • 4:54 - 4:58
    this mean modal comes from the word mode
  • 4:56 - 5:01
    and this means that vim has multiple
  • 4:58 - 5:03
    operating modes and this is kind of
  • 5:01 - 5:05
    developed from the idea that when you're
  • 5:03 - 5:06
    programming there often times where
  • 5:05 - 5:07
    you're doing different types of things
  • 5:06 - 5:09
    like sometimes you're reading code
  • 5:07 - 5:11
    sometimes you're making small edits to
  • 5:09 - 5:12
    code like you're finding a particular
  • 5:11 - 5:15
    point like changing a little thing
  • 5:12 - 5:17
    somewhere sometimes you're just writing
  • 5:15 - 5:17
    a lot of code in one go like suppose
  • 5:17 - 5:19
    you're just writing a function from
  • 5:17 - 5:20
    scratch and so there's different
  • 5:19 - 5:24
    operating modes for doing these
  • 5:20 - 5:25
    different types of things and so I'm
  • 5:24 - 5:26
    actually want to write this down on the
  • 5:25 - 5:29
    blackboard so I'll have a useful thing
  • 5:26 - 5:33
    to refer to later so when you start vim
  • 5:29 - 5:35
    up it starts up in what's called normal
  • 5:33 - 5:37
    mode and in this mode all the different
  • 5:35 - 5:39
    key combinations behave in one way and
  • 5:37 - 5:40
    then there are different key
  • 5:39 - 5:42
    combinations that switch you between
  • 5:40 - 5:46
    normal mode and other modes which change
  • 5:42 - 5:48
    the meaning of different keys so for the
  • 5:46 - 5:50
    most part you'll be spending most of
  • 5:48 - 5:55
    your time in vim in normal mode or what
  • 5:50 - 5:57
    is called insert mode and to go to
  • 5:55 - 6:00
    insert mode you press the key I for
  • 5:57 - 6:02
    normal mode and to go from insert mode
  • 6:00 - 6:07
    back to normal mode you press the Escape
  • 6:02 - 6:10
    key a little note on notation because
  • 6:07 - 6:11
    we'll need this later in the notation
  • 6:10 - 6:13
    I'm going to be using in this lecture
  • 6:11 - 6:15
    and what's also in the lecture notes and
  • 6:13 - 6:16
    what vim uses to give you feedback they
  • 6:15 - 6:18
    have a couple different ways of talking
  • 6:16 - 6:19
    about different keys so when they're
  • 6:18 - 6:20
    talking about bare keys like just the
  • 6:19 - 6:23
    eye key on your keyboard they'll just
  • 6:20 - 6:24
    say eye but for a different key
  • 6:23 - 6:27
    combinations like when you press control
  • 6:24 - 6:30
    and something like say control V it's
  • 6:27 - 6:32
    notated in one of like approximately
  • 6:30 - 6:35
    three ways one way that can be notated
  • 6:32 - 6:37
    is a caret and then the control
  • 6:35 - 6:40
    character so this is control V another
  • 6:37 - 6:41
    way this might be written I think we've
  • 6:40 - 6:42
    written it this way in
  • 6:41 - 6:43
    lecture notes as control-v this is
  • 6:42 - 6:46
    probably the one you're more used to
  • 6:43 - 6:49
    seeing and then in some parts of them
  • 6:46 - 6:51
    this is written as angle brackets C - V
  • 6:49 - 6:54
    close angle bracket so just a little bit
  • 6:51 - 6:54
    of notation that will be useful later
  • 6:54 - 6:59
    so yeah vim has a couple different modes
  • 6:57 - 7:02
    where normal mode is designed for
  • 6:59 - 7:04
    navigating around a file reading things
  • 7:02 - 7:06
    going from file to file things like that
  • 7:04 - 7:08
    and then insert mode is where you type
  • 7:06 - 7:10
    in text so most keys that you press here
  • 7:08 - 7:12
    will just go into your text buffer where
  • 7:10 - 7:14
    as keys that you press here are not
  • 7:12 - 7:15
    being put into the buffer and instead
  • 7:14 - 7:20
    are used for things like navigation or
  • 7:15 - 7:22
    making edits and actually the picture is
  • 7:20 - 7:23
    a little bit more complicated than this
  • 7:22 - 7:24
    there are a whole bunch of other modes
  • 7:23 - 7:26
    and I'm just gonna write them down here
  • 7:24 - 7:29
    because we'll have them here to refer to
  • 7:26 - 7:33
    later and so if it also has a replace
  • 7:29 - 7:34
    mode for rather than inserting text and
  • 7:33 - 7:36
    kind of pushing what's ahead of it
  • 7:34 - 7:38
    forward it will overwrite text and then
  • 7:36 - 7:45
    it has a bunch of different modes for
  • 7:38 - 7:48
    selection so it has a mode called visual
  • 7:45 - 7:54
    mode and then it has visual line and
  • 7:48 - 7:57
    visual block this one is enter via the R
  • 7:54 - 8:02
    key this was entered via the V key this
  • 7:57 - 8:06
    one is entered via shift B and this one
  • 8:02 - 8:13
    is entered via control V and then
  • 8:06 - 8:17
    there's the command line mode which is
  • 8:13 - 8:17
    entered via the colon key
  • 8:19 - 8:31
    okay so now that we have that on the
  • 8:21 - 8:35
    board to refer to later we can actually
  • 8:31 - 8:36
    try some of this out all right so one
  • 8:35 - 8:39
    thing we noticed looking at that picture
  • 8:36 - 8:40
    is that to go from normal mode to any of
  • 8:39 - 8:42
    the other modes we press some key but to
  • 8:40 - 8:43
    go from any of the other modes back to
  • 8:42 - 8:45
    normal mode where we spend a lot of our
  • 8:43 - 8:49
    time we use the Escape key on our
  • 8:45 - 8:50
    keyboard so for this reason since you
  • 8:49 - 8:52
    under pressing the Escape key a lot when
  • 8:50 - 8:54
    using vim a lot of programmers rebind
  • 8:52 - 8:55
    one of the keys on their keyboard to be
  • 8:54 - 8:57
    escape because it's really inconvenient
  • 8:55 - 8:58
    to reach up with your left pinkie to
  • 8:57 - 9:00
    press that tiny little Escape key in the
  • 8:58 - 9:02
    corner of your keyboard and so a lot of
  • 9:00 - 9:05
    people use the caps lock key instead so
  • 9:02 - 9:07
    it's right there in the home row and we
  • 9:05 - 9:14
    have some links in the lecture notes for
  • 9:07 - 9:16
    how you can do this key rebinding okay
  • 9:14 - 9:18
    so now that we've talked about kind of
  • 9:16 - 9:19
    one of the core ideas of vim the idea of
  • 9:18 - 9:21
    modal editing we can talk about some of
  • 9:19 - 9:23
    the basics like how do you open up this
  • 9:21 - 9:26
    text editor how do you open file save
  • 9:23 - 9:28
    files and things like that and so this
  • 9:26 - 9:30
    is a command line based program although
  • 9:28 - 9:32
    there are some graphical variants and
  • 9:30 - 9:34
    the way you start this program is by
  • 9:32 - 9:36
    running vim one thing you might notice
  • 9:34 - 9:38
    is that in the bottom left corner of my
  • 9:36 - 9:40
    screen they actually saw what I just
  • 9:38 - 9:42
    typed this will be useful later in this
  • 9:40 - 9:44
    lecture where I'm actually typing in
  • 9:42 - 9:45
    commands for vim and I'll be saying what
  • 9:44 - 9:48
    I'm typing but you'll also see it on the
  • 9:45 - 9:50
    screen so if I press ctrl C see it says
  • 9:48 - 9:56
    ctrl C over there is that text big
  • 9:50 - 9:58
    enough for everybody to read great okay
  • 9:56 - 10:00
    so the way we open vim is just by
  • 9:58 - 10:02
    running the program vim on our command
  • 10:00 - 10:04
    line and this comes pre-installed on
  • 10:02 - 10:05
    most systems and if you don't have it
  • 10:04 - 10:08
    you can install it using your package
  • 10:05 - 10:09
    manager vim can also take an argument if
  • 10:08 - 10:11
    we want to use it to edit a particular
  • 10:09 - 10:13
    file instead of just opening up the
  • 10:11 - 10:15
    program then later opening a file so for
  • 10:13 - 10:17
    example I have a file in this directory
  • 10:15 - 10:20
    this is actually the lecture notes for
  • 10:17 - 10:22
    this lecture so I can do vim editors MD
  • 10:20 - 10:26
    and press ENTER and then boom them is
  • 10:22 - 10:30
    started and then in this lecture I'm not
  • 10:26 - 10:33
    running vim in the completely Exton I've
  • 10:30 - 10:35
    configured a couple of things that
  • 10:33 - 10:37
    behave a little bit nicer by defaults
  • 10:35 - 10:38
    little things like having line numbers
  • 10:37 - 10:40
    on the left or having some more status
  • 10:38 - 10:41
    information on the bottom and if you
  • 10:40 - 10:43
    want to start with this default
  • 10:41 - 10:44
    configuration we have a link to this in
  • 10:43 - 10:49
    the lecture notes so you can get a
  • 10:44 - 10:51
    slightly more sane config by default. So,
  • 10:49 - 10:53
    once you've opened Vim, what do you do?
  • 10:51 - 10:55
    Well, as I said earlier, Vim starts in
  • 10:53 - 10:58
    normal mode, so if I just start typing
  • 10:55 - 11:00
    letters like, say, type X it didn't insert
  • 10:58 - 11:02
    X into the buffer. You can see the cursor
  • 11:00 - 11:04
    up in the top left: it actually deleted
  • 11:02 - 11:07
    one of the characters. That's because I'm
  • 11:04 - 11:09
    in normal mode, not insert mode. So insert
  • 11:07 - 11:10
    mode is basically what you're used to with
  • 11:09 - 11:11
    all the other text editors you've used
  • 11:10 - 11:12
    in the past, where there's a cursor
  • 11:11 - 11:15
    somewhere, you press the character, and it
  • 11:12 - 11:18
    just goes into your buffer. I'm instead
  • 11:15 - 11:20
    in vim you start a normal mode and you
  • 11:18 - 11:22
    can press I to go into insert mode so
  • 11:20 - 11:24
    see I've pressed I and then in the
  • 11:22 - 11:26
    bottom left notice that it says - -
  • 11:24 - 11:28
    insert the bottom left always tells you
  • 11:26 - 11:30
    what mode you're in unless this normal
  • 11:28 - 11:31
    mode in which case it's blank and now
  • 11:30 - 11:33
    that I'm an insert mode if I press the X
  • 11:31 - 11:36
    character for example see it just gets
  • 11:33 - 11:37
    inserted into my text buffer and I can
  • 11:36 - 11:40
    backspace over at type other stuff and
  • 11:37 - 11:41
    now my text editor kind of behaves like
  • 11:40 - 11:44
    you'd expect any other program to behave
  • 11:41 - 11:46
    so from this point how to go back to
  • 11:44 - 11:49
    normal mode if I want to stop inserting
  • 11:46 - 11:52
    characters. Yes, exactly. I press escape.
  • 11:49 - 11:54
    And, that's the symbol my keystroke
  • 11:52 - 11:59
    visualizer uses for escape, so
  • 11:54 - 12:01
    just be aware of that. And then, Vim has
  • 11:59 - 12:03
    this idea, that using the mouse is
  • 12:01 - 12:05
    inefficient, like your hands are on the
  • 12:03 - 12:06
    keyboard, moving your hand over to the
  • 12:05 - 12:08
    mouse takes a lot of time, right, like you
  • 12:06 - 12:10
    don't want to waste those couple of
  • 12:08 - 12:11
    milliseconds while you're programming,
  • 12:10 - 12:14
    like in the middle of things. So, instead,
  • 12:11 - 12:16
    all Vim functionality can be accessed
  • 12:14 - 12:17
    just through the keyboard. And, it's all
  • 12:16 - 12:19
    sorts of things you might be used to
  • 12:17 - 12:21
    doing like opening files by going, like,
  • 12:19 - 12:23
    file open, or file save, or things like
  • 12:21 - 12:25
    that, or instead access through the
  • 12:23 - 12:28
    keyboard. And, how is that done? That's
  • 12:25 - 12:29
    done through one of the other Vim modes
  • 12:28 - 12:32
    that are on the board over there. In
  • 12:29 - 12:34
    particular, through command line mode. So,
  • 12:32 - 12:36
    if you're in normal mode, and you press
  • 12:34 - 12:39
    the ":" key, you'll notice that the
  • 12:36 - 12:41
    cursor - I guess my visualizer is covering
  • 12:39 - 12:43
    the thing right now but it's gone - the
  • 12:41 - 12:46
    cursor jumps to the bottom - the bottom
  • 12:43 - 12:49
    left - and it shows that ":" I just typed.
  • 12:46 - 12:50
    Now, I can type in a command. So, you can
  • 12:49 - 12:52
    think of this almost like the command
  • 12:50 - 12:53
    shell that we've talked been talking
  • 12:52 - 12:54
    about over the last few days, except this
  • 12:53 - 12:56
    is Vim's
  • 12:54 - 12:57
    command shell, so you give Vim commands
  • 12:56 - 12:59
    here, instead of shell commands. And
  • 12:57 - 13:01
    there are a bunch of built-in commands
  • 12:59 - 13:03
    that do all the things that you're used
  • 13:01 - 13:04
    to. Like, for example, one command that you
  • 13:03 - 13:06
    might want to know is how to quit this
  • 13:04 - 13:07
    editor. You might notice that if you're in
  • 13:06 - 13:09
    normal mode, I can press "Escape" to go
  • 13:07 - 13:12
    back from command line mode to normal
  • 13:09 - 13:14
    mode, and I press "control C", unlike what
  • 13:12 - 13:16
    happens to a lot of programs, this doesn't
  • 13:14 - 13:18
    quit Vim. So, how do I quit Vim? I can
  • 13:16 - 13:20
    press ":", and then go into command
  • 13:18 - 13:23
    line mode, and then I can type in the
  • 13:20 - 13:25
    command "quit". "Q-U-I-T". You'll see that I
  • 13:23 - 13:29
    - maybe I should move this over to the
  • 13:25 - 13:31
    middle or something - see, it says ":quit"
  • 13:29 - 13:33
    and I press ENTER, and it quits Vim. I can
  • 13:31 - 13:35
    open Vim up again. There's actually a
  • 13:33 - 13:38
    short form for this command, just ":q", and
  • 13:35 - 13:40
    that'll do the same thing. And, there are a
  • 13:38 - 13:43
    bunch of other useful commands like this.
  • 13:40 - 13:45
    So, some other handy ones to know are
  • 13:43 - 13:48
    how do you save a file? So, suppose I make
  • 13:45 - 13:51
    some edits here, like "hello world".
  • 13:48 - 13:54
    So, I pressed "i" to go into insert mode - or
  • 13:51 - 13:56
    let me redo that - I press "i" to go into
  • 13:54 - 14:02
    insert mode. Right now, I can use the down
  • 13:56 - 14:03
    arrow to... I think I've slightly I
  • 14:02 - 14:07
    should fix that. Can you fix the config,
  • 14:03 - 14:12
    actually, John? Never mind that.
  • 14:07 - 14:15
    Okay, so, suppose I go down to this line,
  • 14:12 - 14:17
    and I press "i" to go into insert mode, and
  • 14:15 - 14:19
    type in some text, and then press "escape"
  • 14:17 - 14:21
    to go back to normal mode. Now, how do I
  • 14:19 - 14:23
    actually save this file? Well, there's
  • 14:21 - 14:26
    another command for that. So, ":" to go
  • 14:23 - 14:30
    into command mode, and then I can type "W"...
  • 14:26 - 14:33
    ...and press "Enter". "W" stands for write. And,
  • 14:30 - 14:36
    it says in the bottom "editors.md"
  • 14:33 - 14:38
    whatever blah blah written. And, so, this
  • 14:36 - 14:40
    means it saved the file and so now if I
  • 14:38 - 14:42
    ":q" to quit and open the same file,
  • 14:40 - 14:47
    again, you'll see that the changes have
  • 14:42 - 14:49
    been persisted. There are a couple other
  • 14:47 - 14:50
    there's... So, there's a ton of different
  • 14:49 - 14:53
    Vim commands that are useful for
  • 14:50 - 14:56
    different reasons. But, I'll just explain
  • 14:53 - 14:59
    a couple more to you now. One command
  • 14:56 - 15:02
    that's really useful is help. ":help"
  • 14:59 - 15:04
    And you can do ":help", and then type in a
  • 15:02 - 15:06
    particular key, or a particular command,
  • 15:04 - 15:09
    and get help for that keystroke or that
  • 15:06 - 15:11
    command. So, if I want to know what
  • 15:09 - 15:15
    ":w" does, I
  • 15:11 - 15:21
    can do : help : W, and that'll give me
  • 15:15 - 15:23
    the documentation on : w or : write. If I
  • 15:21 - 15:26
    do : q, it'll close this window and bring
  • 15:23 - 15:29
    me back to where I was before.
  • 15:26 - 15:35
    And, notice that ":help :w" is different
  • 15:29 - 15:38
    from ":help w", because the W key is the W
  • 15:35 - 15:41
    that, like, when you're in normal mode and
  • 15:38 - 15:42
    press W, what happens is just the W key
  • 15:41 - 15:44
    here without the ":".
  • 15:42 - 15:50
    And, if I look for help for ":w", that's
  • 15:44 - 15:56
    the help for the W command. So, now you
  • 15:50 - 15:58
    basically have the bare fundamentals
  • 15:56 - 16:01
    needed to use them. right? You can open
  • 15:58 - 16:03
    the editor, use it to edit a particular
  • 16:01 - 16:05
    file, press "i" to go into insert mode and
  • 16:03 - 16:07
    type in some text, press "escape" to go
  • 16:05 - 16:10
    back to normal mode, and then :w to save
  • 16:07 - 16:11
    your changes, :w to quit. So, like already
  • 16:10 - 16:14
    you have the bare fundamentals necessary
  • 16:11 - 16:17
    to edit files using Vim, albeit somewhat
  • 16:14 - 16:24
    inefficiently. So, any questions so far?
  • 16:17 - 16:25
    Yeah in the back. Yeah so the question is,
  • 16:24 - 16:27
    What's the benefit of the
  • 16:25 - 16:29
    normal mode? And, we'll talk about that in
  • 16:27 - 16:32
    more detail, in like five minutes.
  • 16:29 - 16:33
    But, in short, insert mode is just for
  • 16:32 - 16:35
    typing in text. So, I'm in insert mode, I
  • 16:33 - 16:36
    can type in text. But, when I'm
  • 16:35 - 16:39
    programming, I actually spend a lot of
  • 16:36 - 16:41
    time moving around my file making small
  • 16:39 - 16:42
    little changes. So, I go here and like, oh
  • 16:41 - 16:45
    maybe I want to change this HTTPS link to
  • 16:42 - 16:48
    an HTTP.
  • 16:45 - 16:50
    I can make like small point edits, things
  • 16:48 - 16:51
    like that, in normal mode. And we'll see a
  • 16:50 - 16:53
    whole lot more of that in about five
  • 16:51 - 16:59
    minutes. Good question!
  • 16:53 - 17:05
    Any other questions? Okay cool. So, moving
  • 16:59 - 17:11
    along, one other thing that's kind of
  • 17:05 - 17:13
    useful to know, I think, is, at a high
  • 17:11 - 17:15
    level, Vim's model of
  • 17:13 - 17:16
    buffers versus windows versus tabs. So,
  • 17:15 - 17:18
    it's probably the case that whatever
  • 17:16 - 17:20
    program you were using before, like
  • 17:18 - 17:22
    Sublime Text or VS Code or whatever,
  • 17:20 - 17:23
    you could open multiple files in it,
  • 17:22 - 17:25
    right, and you could probably have
  • 17:23 - 17:27
    multiple tabs open and have multiple
  • 17:25 - 17:29
    windows open of your editor. So, Vim also
  • 17:27 - 17:31
    has a notion of those different things.
  • 17:29 - 17:34
    But, its model is a little bit different
  • 17:31 - 17:36
    than most other programs. So, Vim
  • 17:34 - 17:38
    maintains a set of open buffers - that's
  • 17:36 - 17:40
    the word it uses for open files - and so,
  • 17:38 - 17:42
    it has a set of open files, and then kind
  • 17:40 - 17:44
    of separately from that, you can have a
  • 17:42 - 17:47
    number of tabs, and tabs can have windows.
  • 17:44 - 17:47
    The kind of weird thing which makes Vim
  • 17:47 - 17:49
    a little bit different than the
  • 17:47 - 17:51
    program you've probably used in the past is
  • 17:49 - 17:52
    that there isn't necessarily a
  • 17:51 - 17:55
    one-to-one correspondence between
  • 17:52 - 17:57
    buffers and windows. So, one thing I can
  • 17:55 - 17:58
    do, for example, here - and we'll show you
  • 17:57 - 18:01
    the key combinations and stuff for this
  • 17:58 - 18:02
    later - but one thing you can do is create
  • 18:01 - 18:04
    two different windows. So, I have one
  • 18:02 - 18:07
    window up here, and then one window down
  • 18:04 - 18:09
    here. And, notice that the same files open
  • 18:07 - 18:11
    in both windows. So, if I make some edits
  • 18:09 - 18:12
    over here, they actually happen in the
  • 18:11 - 18:14
    bottom window, as well, because it's the
  • 18:12 - 18:14
    same buffer that's open in both windows.
  • 18:14 - 18:18
    And, this is kind of useful, for, say,
  • 18:17 - 18:20
    looking at two different parts of a
  • 18:18 - 18:21
    single file at the same time. Like, so you
  • 18:20 - 18:23
    want to be able to look at the top of a
  • 18:21 - 18:25
    file, say at an import to your program,
  • 18:23 - 18:28
    while you're down below, working
  • 18:25 - 18:29
    somewhere else. So, this is one helpful
  • 18:28 - 18:33
    thing to keep in mind, that Vim has this
  • 18:29 - 18:36
    idea of - there are a number of tabs, and
  • 18:33 - 18:38
    each tab has some number of windows, and
  • 18:36 - 18:41
    then each window has, uh, corresponds to
  • 18:38 - 18:42
    some buffer. But, a particular buffer can
  • 18:41 - 18:44
    be open in zero or more windows at a
  • 18:42 - 18:46
    time. Just one thing that confused me
  • 18:44 - 18:48
    when I was initially learning Vim, so I
  • 18:46 - 18:51
    want to explain that early on. And then,
  • 18:48 - 18:54
    the ":q" command, which we talked about
  • 18:51 - 18:55
    earlier, is not exactly quit. It's kind of
  • 18:54 - 18:57
    "close the current window", and then, when
  • 18:55 - 18:59
    there are no more open windows, Vim will
  • 18:57 - 19:01
    quit. So, here, if I do ":q", it'll only
  • 18:59 - 19:04
    close the window, I think, on the top here
  • 19:01 - 19:06
    because that's the one I was in, and, now,
  • 19:04 - 19:08
    the remaining window becomes fullscreen.
  • 19:06 - 19:10
    I can do : Q again to close this. Now we're in
  • 19:08 - 19:15
    the second tab that I'd opened. If I do :Q
  • 19:10 - 19:16
    a final time, okay, now, Vim exits. And if
  • 19:15 - 19:18
    you don't want to press ":q" way too many
  • 19:16 - 19:21
    times... Okay, so, here I have three split
  • 19:18 - 19:25
    windows. If I do ":qa", for quit all, it
  • 19:21 - 19:25
    closes all the open windows.
  • 19:25 - 19:31
    All right, so, now, to answer your question of
  • 19:29 - 19:33
    "What is normal mode actually for?" This is
  • 19:31 - 19:34
    another, really cool idea in Vim, and I
  • 19:33 - 19:36
    think this is actually, like, the most
  • 19:34 - 19:39
    fundamentally interesting idea of this
  • 19:36 - 19:42
    program. It's that, like, you're all
  • 19:39 - 19:44
    programmers, you like programming; Vim has
  • 19:42 - 19:47
    this idea that Vim's normal mode, like,
  • 19:44 - 19:50
    Vim's interface, itself, is a programming
  • 19:47 - 19:51
    language. And, let me repeat that.
  • 19:50 - 19:53
    That's like a kind of fundamentally
  • 19:51 - 19:54
    interesting idea: the interface is a
  • 19:53 - 19:56
    programming language.
  • 19:54 - 19:58
    What does that mean? It means that
  • 19:56 - 19:59
    different key combinations have
  • 19:58 - 20:00
    different effects, and, once you learn the
  • 19:59 - 20:02
    different effects, you can actually
  • 20:00 - 20:03
    combine them together - just like in a
  • 20:02 - 20:05
    programming language - you can learn
  • 20:03 - 20:06
    different functions and stuff and then
  • 20:05 - 20:08
    glue them all together to make an
  • 20:06 - 20:10
    interesting program. In the same way, once
  • 20:08 - 20:11
    you learn Vim's different movement and
  • 20:10 - 20:14
    editing commands, and things like that,
  • 20:11 - 20:17
    you can talk to Vim by programming Vim
  • 20:14 - 20:19
    through its interface. And, once this
  • 20:17 - 20:21
    becomes muscle memory, you can basically
  • 20:19 - 20:22
    edit files at the speed at which you
  • 20:21 - 20:24
    think. Like at least for me, I don't think
  • 20:22 - 20:25
    I've been able to do this with any other
  • 20:24 - 20:29
    text editor that I've used in the past,
  • 20:25 - 20:31
    but this one gets pretty close. So, let's
  • 20:29 - 20:34
    dig into how exactly normal mode works.
  • 20:31 - 20:36
    So, you can try to follow along with this,
  • 20:34 - 20:38
    like, open up some random file in Vim, and
  • 20:36 - 20:40
    follow some of the key combinations I
  • 20:38 - 20:42
    type in. So, one basic thing that you
  • 20:40 - 20:44
    might want to do, is just navigate around
  • 20:42 - 20:46
    a buffer. Like, move your cursor up/down/
  • 20:44 - 20:49
    left/right. And, so the way you do that in
  • 20:46 - 20:51
    Vim, is using the hjkl keys, not the arrow
  • 20:49 - 20:52
    keys. Though they do work by default, try
  • 20:51 - 20:54
    to avoid them, because you don't want to
  • 20:52 - 20:55
    have to move your hand all the way over
  • 20:54 - 20:57
    to the arrow keys. Like, there's a ton of
  • 20:55 - 21:01
    time you're wasting, right? HJKL is right
  • 20:57 - 21:04
    on the home row. And, so, J moves down, K
  • 21:01 - 21:06
    moves up, H moves left, and L moves right.
  • 21:04 - 21:09
    And, this may seem a little unintuitive
  • 21:06 - 21:10
    now; there was some historical reason for
  • 21:09 - 21:13
    it, like, the keyboard the original vi
  • 21:10 - 21:15
    developer used had the hjkl keys, like,
  • 21:13 - 21:17
    labeled, and arranged in a way that made
  • 21:15 - 21:19
    this more reasonable. But, this will very
  • 21:17 - 21:20
    soon become muscle memory. So, this is the
  • 21:19 - 21:24
    basic way you can move your cursor
  • 21:20 - 21:26
    around while in normal mode. Now, what
  • 21:24 - 21:28
    else can you do? Well, if we had to move
  • 21:26 - 21:30
    around files like this, it'd be really
  • 21:28 - 21:32
    slow. We don't want to have to
  • 21:30 - 21:33
    hold down these keys, and like, wait for a
  • 21:32 - 21:34
    long time for Vim to do its thing. And
  • 21:33 - 21:36
    so, there are all these other, different
  • 21:34 - 21:37
    key combinations for doing different
  • 21:36 - 21:38
    movements.
  • 21:37 - 21:39
    Also, by the way, this is all in the
  • 21:38 - 21:41
    lecture notes, so you don't need to
  • 21:39 - 21:44
    memorize every single key and its
  • 21:41 - 21:45
    meaning right now. Just try to understand
  • 21:44 - 21:48
    the overall idea that Vim's interface is
  • 21:45 - 21:50
    a programming language. So, another thing
  • 21:48 - 21:53
    you can do is press the W key. This moves
  • 21:50 - 21:55
    the cursor forward by one word. And then,
  • 21:53 - 21:58
    similarly, the "B" key moves the cursor
  • 21:55 - 21:59
    backward by one word. So, this allows
  • 21:58 - 22:02
    slightly more efficient movement within
  • 21:59 - 22:04
    the line. There's also the "E" key for
  • 22:02 - 22:07
    moving to the end of a word. I'm going to
  • 22:04 - 22:08
    move this over a little bit. So, if I'm
  • 22:07 - 22:10
    here, for example, and I press the "E" key
  • 22:08 - 22:13
    it'll go to the end of this word, end of
  • 22:10 - 22:16
    this word, end of the next word and so on.
  • 22:13 - 22:18
    You can also move by whole lines, so zero
  • 22:16 - 22:20
    moves to the beginning of a line, dollar
  • 22:18 - 22:23
    sign moves to the end of a line, and the
  • 22:20 - 22:26
    caret key moves to the first non-empty
  • 22:23 - 22:32
    character on a line. So, let me find one
  • 22:26 - 22:34
    of those, for example. So, here, my
  • 22:32 - 22:35
    cursor's right here; if I press 0, my
  • 22:34 - 22:37
    cursor goes to the beginning of the line,
  • 22:35 - 22:40
    dollar sign, end of the current line; and
  • 22:37 - 22:41
    if I press caret, where, like, on what
  • 22:40 - 22:45
    character will the curser end up? Can
  • 22:41 - 22:48
    anybody guess? So, caret goes to the first
  • 22:45 - 22:53
    non-empty character on a line, kind of
  • 22:48 - 22:57
    like Regex caret. Yeah, exactly! It goes
  • 22:53 - 23:00
    to this dash. Let's talk about some more
  • 22:57 - 23:01
    movement commands. There're ways to
  • 23:00 - 23:06
    scroll up and down in a buffer, so
  • 23:01 - 23:09
    control U goes up, and control D scrolls
  • 23:06 - 23:11
    down. So, this is better than holding down
  • 23:09 - 23:13
    the K or J keys, for example. This is a
  • 23:11 - 23:18
    lot slower than moving by entire pages.
  • 23:13 - 23:20
    Control D and control U. There's also
  • 23:18 - 23:22
    ways to move by the entire buffer. So,
  • 23:20 - 23:26
    capital "G" moves all the way down... "gg"
  • 23:22 - 23:28
    moves all the way up. Some of these
  • 23:26 - 23:30
    movement keys are mnemonics; so, they're
  • 23:28 - 23:31
    like, a little bit easier to remember for
  • 23:30 - 23:33
    that reason, right, like, "W" is word, "B"
  • 23:31 - 23:36
    is beginning of word, E is end of word. Those
  • 23:33 - 23:38
    all seem pretty logical. 0, caret and
  • 23:36 - 23:40
    dollar, kind of inspired from Regex, so
  • 23:38 - 23:41
    those make a little bit of sense. There's
  • 23:40 - 23:43
    some other ones that, like, don't
  • 23:41 - 23:44
    necessarily make way too much sense, but,
  • 23:43 - 23:46
    there are only so many keys on your
  • 23:44 - 23:49
    keyboard, so what are you going to do? For
  • 23:46 - 23:49
    example, the "L" key moves your cursor to
  • 23:49 - 23:52
    the lowest
  • 23:49 - 23:55
    line that's shown on the screen. "L" for
  • 23:52 - 24:01
    lowest makes sense, M for middle, and then H for
  • 23:55 - 24:03
    highest, I guess. And, there's a whole
  • 24:01 - 24:04
    bunch of other interesting movements
  • 24:03 - 24:05
    like this. So, we're obviously not going
  • 24:04 - 24:07
    to be able to cover all of them right
  • 24:05 - 24:09
    now, but you'll be able to go through
  • 24:07 - 24:11
    them in the Vim tutor exercise, which is
  • 24:09 - 24:16
    exercise number one for this lecture.
  • 24:11 - 24:18
    Some other ones I want to talk about now -
  • 24:16 - 24:20
    maybe I'll talk about one more. There's
  • 24:18 - 24:21
    another movement called "find". This is
  • 24:20 - 24:23
    also kind of useful. Suppose I'm on this
  • 24:21 - 24:25
    line, and I want to jump to the first
  • 24:23 - 24:27
    character that equal's to... Like, I
  • 24:25 - 24:31
    want to jump to the first "o". I can press
  • 24:27 - 24:34
    "fo", and my cursor moves to the first
  • 24:31 - 24:35
    "o". I've like, found "o". I can do fw and
  • 24:34 - 24:40
    it'll move to the first "w", which I think
  • 24:35 - 24:41
    is right here. fc: find the first C. I can
  • 24:40 - 24:45
    also do the same thing, but backwards. If
  • 24:41 - 24:48
    I do capital F, w, I can find the W that's
  • 24:45 - 24:50
    before it. Capital F, s: find the s that's
  • 24:48 - 24:53
    before that. And then, there's a variant
  • 24:50 - 24:57
    of f, for find: t for to, so I can jump to
  • 24:53 - 24:59
    O, and it jumps, like, until it's found o.
  • 24:57 - 25:03
    But not on top of it, right before it. And
  • 24:59 - 25:05
    capital T say, t, jumps backwards to the t
  • 25:03 - 25:07
    except not all the way on top of it, one
  • 25:05 - 25:10
    character before. And, so, you can already
  • 25:07 - 25:11
    see that idea I talked about, of like, Vim
  • 25:10 - 25:13
    is a programming language; you can, like,
  • 25:11 - 25:15
    compose these commands. "F", and "T", are
  • 25:13 - 25:17
    "find", and "to", and you can say "find" a
  • 25:15 - 25:20
    particular character, or jump "to" a
  • 25:17 - 25:22
    particular character. So, those are a
  • 25:20 - 25:27
    couple of Vim movement commands. So, any
  • 25:22 - 25:32
    questions about those so far? So this is -
  • 25:27 - 25:34
    yeah, question? Or... no? Okay, cool. So,
  • 25:32 - 25:36
    those are Vim movement commands.
  • 25:34 - 25:38
    This is how you can navigate around a
  • 25:36 - 25:40
    file quickly in normal mode. Now, another
  • 25:38 - 25:43
    category of useful commands are editing
  • 25:40 - 25:44
    commands. So, one we kind of already
  • 25:43 - 25:47
    talked about is the "i" command
  • 25:44 - 25:48
    for moving from "normal" mode to "insert"
  • 25:47 - 25:51
    mode, where you can start just writing
  • 25:48 - 25:52
    text. So, suppose I go up here and I press
  • 25:51 - 25:57
    "i". Now I can type in whatever text I want
  • 25:52 - 25:58
    "Hello world", "enter". Then, press
  • 25:57 - 26:01
    "escape" to go back to normal mode, and
  • 25:58 - 26:02
    I've made a change to my buffer. But,
  • 26:01 - 26:04
    there are a whole bunch of other
  • 26:02 - 26:06
    commands for making efficient edits
  • 26:04 - 26:08
    that makes sense for when you're dealing
  • 26:06 - 26:09
    with programming languages. So, one useful
  • 26:08 - 26:11
    command that I accidentally used earlier,
  • 26:09 - 26:13
    before teaching you about it, is the "o"
  • 26:11 - 26:16
    command. So, suppose my cursor is, like,
  • 26:13 - 26:18
    over here, and if I press "o", from normal
  • 26:16 - 26:19
    mode, what it does, is it opens a new line
  • 26:18 - 26:22
    below where my cursor is.
  • 26:19 - 26:23
    That's what "o" stands for. And it, so it
  • 26:22 - 26:25
    creates a new line, and it put me into
  • 26:23 - 26:27
    insert mode. So, now I can start typing in
  • 26:25 - 26:30
    some text, press escape, and go back to
  • 26:27 - 26:32
    normal mode. And then, just like the "o"
  • 26:30 - 26:36
    command, there's a capital "O" command, so
  • 26:32 - 26:38
    if I'm here and I do capital "O", it puts
  • 26:36 - 26:42
    me into insert mode above where I
  • 26:38 - 26:44
    currently am. There's another Vim command
  • 26:42 - 26:48
    for deleting things. So, suppose my cursor
  • 26:44 - 26:52
    is, like, on top of this word right here,
  • 26:48 - 26:54
    and I press the D key. "D" for delete. Oh,
  • 26:52 - 26:56
    nothing happens; turns out that the D key
  • 26:54 - 26:58
    needs to be combined with a movement
  • 26:56 - 27:00
    command. So, remember we just talked about
  • 26:58 - 27:03
    different movement commands, like hjkl,
  • 27:00 - 27:04
    and, like, word, and backward word, and
  • 27:03 - 27:08
    things like that.
  • 27:04 - 27:12
    So, I press D. Whoops. I press D and I can
  • 27:08 - 27:14
    press W, and it's deleted a word. So, let
  • 27:12 - 27:17
    me undo that. Undoing in Vim is just u for
  • 27:14 - 27:20
    undo. So, notice my cursor's right here. I
  • 27:17 - 27:22
    do "dw": it's deleted a word. I can move
  • 27:20 - 27:25
    around, and then delete another word.
  • 27:22 - 27:28
    Suppose I'm - uh, keeps getting in the way
  • 27:25 - 27:29
    Suppose I'm, like, somewhere in the middle
  • 27:28 - 27:31
    of a word, and I want to delete to the end
  • 27:29 - 27:36
    of a word. Any guesses for what
  • 27:31 - 27:39
    combination of keys I'd use for that? "d"
  • 27:36 - 27:44
    and what? de, exactly. Delete to the end of
  • 27:39 - 27:47
    the word. Another useful editing command
  • 27:44 - 27:49
    is the c command. c stands for change. So,
  • 27:47 - 27:51
    change is really similar to delete,
  • 27:49 - 27:52
    except change puts you in insert mode,
  • 27:51 - 27:54
    because, like, I want to delete a thing,
  • 27:52 - 27:57
    but change it to something else. So, if
  • 27:54 - 28:00
    I'm here, and I do "ce", it's like, change
  • 27:57 - 28:01
    to the end of the word. And, it gets rid
  • 28:00 - 28:03
    of the contents until the end of the
  • 28:01 - 28:04
    word, and notice it put me in insert mode.
  • 28:03 - 28:07
    So now, whatever characters I type go
  • 28:04 - 28:11
    into the buffer. If I press "escape", I go
  • 28:07 - 28:13
    back into normal mode. And so, c and d are
  • 28:11 - 28:16
    analogs: they both take motions as
  • 28:13 - 28:17
    arguments. And, they will either delete
  • 28:16 - 28:21
    that motion, or change
  • 28:17 - 28:24
    that motion. So, for example, if you press
  • 28:21 - 28:26
    the c key, there's also this pattern that,
  • 28:24 - 28:28
    if you press a particular editing key
  • 28:26 - 28:30
    twice, it'll have that effect on the
  • 28:28 - 28:33
    given line. So, if I press "dd", that
  • 28:30 - 28:34
    deletes the line. If I press "cc", that
  • 28:33 - 28:36
    deletes the given line, but puts me in
  • 28:34 - 28:40
    insert mode, so I can replace it with
  • 28:36 - 28:43
    some other line. We'll cover a couple
  • 28:40 - 28:44
    other, uh, editing commands, because then
  • 28:43 - 28:47
    later we'll see how all these things
  • 28:44 - 28:49
    interact together. So, another useful one
  • 28:47 - 28:50
    is the x command. So, suppose my cursor is
  • 28:49 - 28:52
    over some particular character. If I
  • 28:50 - 28:58
    press "x", it just deletes that
  • 28:52 - 29:00
    character. There's another command called
  • 28:58 - 29:02
    r. If I'm over a particular character, and
  • 29:00 - 29:04
    I press "r", it takes another character as
  • 29:02 - 29:05
    an argument, and it replaces that
  • 29:04 - 29:13
    particular character with some other
  • 29:05 - 29:14
    character. And, I'll cover a couple more
  • 29:13 - 29:16
    editing commands. So, I think one I
  • 29:14 - 29:18
    talked about a moment ago - but, of course
  • 29:16 - 29:19
    you can undo changes you've made in Vim.
  • 29:18 - 29:22
    And the way you do that is by pressing
  • 29:19 - 29:23
    "u" while you're in normal mode. So, u for
  • 29:22 - 29:25
    undo is pretty easy to remember. So, I
  • 29:23 - 29:26
    press "u" a whole bunch of times; it's
  • 29:25 - 29:29
    undone all the changes I've made. And
  • 29:26 - 29:31
    then, the opposite of undo is, of course,
  • 29:29 - 29:41
    redo. And, the binding for that in Vim is
  • 29:31 - 29:42
    control + R. All right, one other editing
  • 29:41 - 29:55
    command I'm going to talk about is copy
  • 29:42 - 29:56
    and paste because-oh yes, question? That's
  • 29:55 - 29:58
    a - that's a great question! So, the
  • 29:56 - 30:00
    question is, "Does 'undo' undo everything
  • 29:58 - 30:01
    you've done since you've gone into
  • 30:00 - 30:02
    insert mode, or just the last character?"
  • 30:01 - 30:03
    It's - it's actually a little bit more
  • 30:02 - 30:06
    complicated than that.
  • 30:03 - 30:08
    "Undo" does, like, undoes the last change
  • 30:06 - 30:09
    you've made. So, if you went into insert
  • 30:08 - 30:10
    mode, and typed in some stuff, and went
  • 30:09 - 30:13
    back into normal mode, and then press "u"
  • 30:10 - 30:15
    for "undo", it'll undo all you've done in
  • 30:13 - 30:16
    insert mode. But, if you've done some
  • 30:15 - 30:18
    other type of editing command, like, say I
  • 30:16 - 30:20
    press "x" to delete a character... If I do
  • 30:18 - 30:24
    "u" for undo, it'll just undo that change
  • 30:20 - 30:26
    that that editing command made. Now, does
  • 30:24 - 30:29
    that answer the question? (Yeah) Great any
  • 30:26 - 30:33
    other questions?
  • 30:29 - 30:35
    Cool. So, I'll talk about copy and paste
  • 30:33 - 30:38
    as well, because that's a popular one. The
  • 30:35 - 30:40
    y command stands for copying, and the p
  • 30:38 - 30:42
    command stands for pasting. y for "copy",
  • 30:40 - 30:43
    because, yank. Like, that's the word they-
  • 30:42 - 30:46
    that's the terminology that
  • 30:43 - 30:49
    Vim uses for copying. And, these commands
  • 30:46 - 30:53
    are- y also takes a motion as an argument.
  • 30:49 - 30:54
    So if I do like, yy, it copies the current
  • 30:53 - 30:56
    line. And, if I press "p" for "paste",
  • 30:54 - 30:57
    notice that now these two lines are
  • 30:56 - 31:00
    identical, because I've just pasted a
  • 30:57 - 31:02
    line below. "u" for "undo". But if I do
  • 31:00 - 31:05
    something like "yw", it's copied the word.
  • 31:02 - 31:05
    And then I can do "p", and it just pasted
  • 31:05 - 31:09
    that word again,
  • 31:05 - 31:11
    right where my cursor was. One useful
  • 31:09 - 31:13
    thing, especially in the context of copy
  • 31:11 - 31:14
    and paste, is to be able to select a
  • 31:13 - 31:16
    block of stuff and copy it, right? Like,
  • 31:14 - 31:17
    this is probably how you used copy and
  • 31:16 - 31:19
    paste in whatever editor you were using
  • 31:17 - 31:21
    before. And so, that's where we get into
  • 31:19 - 31:23
    the visual modes. So, these are another
  • 31:21 - 31:25
    set of modes that are all related to
  • 31:23 - 31:26
    each other, and that can be reached from
  • 31:25 - 31:29
    normal mode, and they're used for
  • 31:26 - 31:31
    selecting chunks of text. So, one mode is,
  • 31:29 - 31:33
    just, regular visual mode. You can enter
  • 31:31 - 31:35
    that by pressing v. And then, once you're
  • 31:33 - 31:37
    in this mode, you can use most of the
  • 31:35 - 31:38
    regular normal mode commands to move
  • 31:37 - 31:40
    your pointer around. And it selects
  • 31:38 - 31:42
    everything in between. So I can use, like,
  • 31:40 - 31:44
    hjkl just to move the cursor, or I can
  • 31:42 - 31:46
    use "w" to move by words, or different
  • 31:44 - 31:48
    things like that, and it will select a
  • 31:46 - 31:49
    block of text. And, once I've selected
  • 31:48 - 31:51
    this block of text there are a whole bunch
  • 31:49 - 31:53
    of different types of useful things you
  • 31:51 - 31:55
    could do with it. One of the most popular
  • 31:53 - 31:57
    things to do is copying this. So, once
  • 31:55 - 32:00
    I've selected, I can do y to copy, and it
  • 31:57 - 32:01
    puts me back into normal mode. And now,
  • 32:00 - 32:03
    it's copied this to the - to the paste
  • 32:01 - 32:05
    buffer. And then if I go somewhere else,
  • 32:03 - 32:08
    and press "p", it pastes in that whole
  • 32:05 - 32:11
    chunk of text I copied. And it's similar
  • 32:08 - 32:14
    to visual mode, which selects kind of a
  • 32:11 - 32:16
    contiguous stream of text. There's visual
  • 32:14 - 32:18
    line mode: that can be reached by
  • 32:16 - 32:20
    pressing capital V, and that selects
  • 32:18 - 32:21
    whole lines at a time. And then there's
  • 32:20 - 32:23
    VISUAL BLOCK mode, which can be selected
  • 32:21 - 32:25
    by pressing "control" + " V", and that can
  • 32:23 - 32:26
    select rectangular blocks of text. So
  • 32:25 - 32:32
    this is something your old editor
  • 32:26 - 32:33
    couldn't do. Alright, so, there's a lot
  • 32:32 - 32:35
    more Vim editing commands to learn.
  • 32:33 - 32:37
    There's lots of, like, really weird and
  • 32:35 - 32:38
    fancy things. Like, for example, the tilde
  • 32:37 - 32:40
    command changes the case of the
  • 32:38 - 32:42
    character, or the selection that you've
  • 32:40 - 32:44
    currently selected. So for example,
  • 32:42 - 32:46
    I can take this, like, Visual Studio Code,
  • 32:44 - 32:48
    and flip the case on the whole thing, by
  • 32:46 - 32:49
    selecting it and pressing tilde. And,
  • 32:48 - 32:50
    there's a whole bunch of other things
  • 32:49 - 32:52
    like that; they get more and more
  • 32:50 - 32:54
    esoteric as you go. So, we're not going to
  • 32:52 - 32:57
    cover all of those, but you'll get to
  • 32:54 - 32:58
    those in the exercises. So, those are Vim
  • 32:57 - 33:01
    editing commands, and a lot of them can
  • 32:58 - 33:02
    be composed with movement commands. So,
  • 33:01 - 33:09
    any questions about either of those so
  • 33:02 - 33:13
    far? Cool. So, moving along, another
  • 33:09 - 33:14
    category of things -of commands- that are
  • 33:13 - 33:17
    mostly relevant to normal mode are
  • 33:14 - 33:19
    counts. So, you can give them a number, to
  • 33:17 - 33:22
    do a particular thing, some number of
  • 33:19 - 33:25
    times. So suppose my cursor is here, and I
  • 33:22 - 33:27
    want to move down, like 1 2 3 4 lines. One
  • 33:25 - 33:29
    way I can do that is by pressing "j" four
  • 33:27 - 33:33
    times - go down four times. "kkkk" goes
  • 33:29 - 33:34
    up four times. But, rather than pressing a
  • 33:33 - 33:37
    particular key again, and again, I can use
  • 33:34 - 33:39
    a count. So if I press "4", "j", it does j
  • 33:37 - 33:40
    four times, right?
  • 33:39 - 33:42
    Vim's interface is a programming
  • 33:40 - 33:46
    language. If I do "4k", it moves up four
  • 33:42 - 33:48
    times. If I am here, and I press "v" to go
  • 33:46 - 33:49
    into visual mode... Okay so now I can move
  • 33:48 - 33:52
    my cursor around, and select blocks of
  • 33:49 - 33:54
    text. I can do, like, "eee" to select a
  • 33:52 - 33:57
    couple of words, but, I could also go back
  • 33:54 - 34:00
    here -v for visual mode- and press three e
  • 33:57 - 34:03
    to select, like, three "ends of words"
  • 34:00 - 34:05
    forward. And then of course these can also
  • 34:03 - 34:08
    be combined with editing commands. So,
  • 34:05 - 34:11
    like, suppose I want to delete seven
  • 34:08 - 34:14
    words. I can do that by moving my cursor
  • 34:11 - 34:18
    somewhere, and doing "7dw". Seven delete
  • 34:14 - 34:19
    words. And so, this is particularly useful
  • 34:18 - 34:21
    for things like, suppose my cursor is
  • 34:19 - 34:22
    somewhere on the screen, and I'm looking
  • 34:21 - 34:24
    somewhere else on the screen, or, I want
  • 34:22 - 34:26
    my cursor to go to that particular line.
  • 34:24 - 34:28
    Notice that I've set up relative line
  • 34:26 - 34:30
    numbering on the left. So, wherever my
  • 34:28 - 34:32
    cursor is, it shows the current line
  • 34:30 - 34:34
    number, but everywhere else, it's just the
  • 34:32 - 34:36
    offset from where I am. Now, suppose my
  • 34:34 - 34:38
    cursor is here, but I want to move down
  • 34:36 - 34:40
    to the like "Microsoft Word" down here, so
  • 34:38 - 34:42
    that's eight lines down. So, what
  • 34:40 - 34:44
    combination of keys would I press, to do
  • 34:42 - 34:46
    that? Like, what's the most efficient way?
  • 34:44 - 34:48
    Yeah, exactly!
  • 34:46 - 34:50
    Let's try that out-8j-and my cursor moved
  • 34:48 - 34:50
    down to this line.
  • 34:51 - 34:58
    Okay. And then, one, final category of key
  • 34:56 - 35:00
    meanings in Vim is something called
  • 34:58 - 35:02
    modifiers. So we have, so far, movement,
  • 35:00 - 35:05
    edits, counts, and, finally, we have
  • 35:02 - 35:07
    modifiers. So, modifiers kind of change
  • 35:05 - 35:09
    the meaning of a movement command a
  • 35:07 - 35:12
    little bit. And, a couple modifiers that
  • 35:09 - 35:15
    are especially useful are the "a" and "i"
  • 35:12 - 35:18
    modifier. So, a stands for like around and
  • 35:15 - 35:20
    "i" stands for inside. And, to see where
  • 35:18 - 35:22
    this is really useful, I can move my
  • 35:20 - 35:22
    cursor to somewhere like here, for
  • 35:22 - 35:25
    example.
  • 35:22 - 35:26
    So, hopefully, most of you are familiar
  • 35:25 - 35:28
    with markdown syntax - and if not it
  • 35:26 - 35:30
    doesn't matter too much. Uh, this is a
  • 35:28 - 35:32
    link in markdown; it's a text rendered in
  • 35:30 - 35:34
    square brackets, and then the link in
  • 35:32 - 35:36
    parentheses. Suppose my cursor is inside
  • 35:34 - 35:38
    here, and I want to change the text
  • 35:36 - 35:40
    corresponding to this link. Well, one way
  • 35:38 - 35:43
    I could do that is, like, move back here
  • 35:40 - 35:45
    with b, and, like, 2dw, and then "i" to go
  • 35:43 - 35:46
    into insert mode. That's one of the
  • 35:45 - 35:48
    many ways I can make this change, and I
  • 35:46 - 35:51
    can type in whatever other thing I want -
  • 35:48 - 35:53
    u to undo, u to undo. Another way I could
  • 35:51 - 35:58
    have done that is change two words - "c2w"
  • 35:53 - 36:00
    - and then type in some other text. But,
  • 35:58 - 36:03
    one final way I could do the same change
  • 36:00 - 36:05
    is using the modifier commands to talk
  • 36:03 - 36:07
    about how I want to interact with these
  • 36:05 - 36:09
    different types of grouping things like
  • 36:07 - 36:12
    parentheses and square brackets. So, one
  • 36:09 - 36:16
    final way of doing this is change inside
  • 36:12 - 36:17
    square brackets-"c" "i" "["-and that puts
  • 36:16 - 36:20
    me into insert mode, after deleting the
  • 36:17 - 36:21
    contents that are inside the brackets. So,
  • 36:20 - 36:23
    do you see how we can take all these
  • 36:21 - 36:24
    different ingredients, like we talked
  • 36:23 - 36:26
    about "change", and we could combine that
  • 36:24 - 36:27
    with different movement commands. We
  • 36:26 - 36:30
    talked about inside, how it's a modifier.
  • 36:27 - 36:33
    And then we talked about, uh... we didn't
  • 36:30 - 36:34
    talk about parentheses. But, if your
  • 36:33 - 36:36
    cursor is hovering over a different, uh,
  • 36:34 - 36:38
    different types of grouping things like
  • 36:36 - 36:40
    parentheses, or square brackets, you can
  • 36:38 - 36:41
    press the percent movement key to jump
  • 36:40 - 36:45
    back and forth between matching
  • 36:41 - 36:50
    parentheses. If I go over here and I do d,
  • 36:45 - 36:52
    i, (, I can delete the contents
  • 36:50 - 36:56
    inside these parentheses. And so, those
  • 36:52 - 36:58
    are Vim, uh, modifiers. I guess we talked
  • 36:56 - 37:00
    about i, but we didn't talk about a. If I
  • 36:58 - 37:02
    do "da(", it deletes a whole,
  • 37:00 - 37:04
    like parenthesized group including the
  • 37:02 - 37:11
    parentheses so I is inside
  • 37:04 - 37:12
    is around or including all right so
  • 37:11 - 37:14
    those are basically the different
  • 37:12 - 37:16
    categories of things you can combine
  • 37:14 - 37:18
    together, when interacting with Vim's
  • 37:16 - 37:20
    interface. So, any questions about that or
  • 37:18 - 37:29
    the overall idea of this interface being
  • 37:20 - 37:32
    a programming language? Cool. So, let's do
  • 37:29 - 37:34
    a quick demo, to kind of demonstrate the
  • 37:32 - 37:36
    power of this editor. And, it will kind of
  • 37:34 - 37:38
    help us see how this tool can work
  • 37:36 - 37:41
    really fast and kind of match the speed
  • 37:38 - 37:44
    at which we think. So, over here is a very
  • 37:41 - 37:45
    broken "fizzbuzz" implementation that
  • 37:44 - 37:47
    doesn't actually print anything.
  • 37:45 - 37:49
    Uh, hopefully, most of you have heard of
  • 37:47 - 37:51
    "fizzbuzz" - if not, I'll explain it super
  • 37:49 - 37:53
    briefly. Uh, "fizzbuzz" is a programming
  • 37:51 - 37:54
    exercise where you print the numbers 1
  • 37:53 - 37:57
    through n, but when the number is
  • 37:54 - 37:59
    divisible by 3, you print fizz - when it's
  • 37:57 - 38:01
    divisible by 5, you print buzz. And, when
  • 37:59 - 38:03
    it's divisible by both 3, and 5. you print
  • 38:01 - 38:05
    fizzbuzz. And, if none of those apply, you
  • 38:03 - 38:09
    just print the number. So, you should
  • 38:05 - 38:13
    print like 1, 2, fizz, 4, buzz, and so on.
  • 38:09 - 38:17
    But, if I run this program, it doesn't
  • 38:13 - 38:20
    print anything here I have them on the
  • 38:17 - 38:22
    left in just a terminal on the right ok
  • 38:20 - 38:24
    so there's a bunch of issues with this
  • 38:22 - 38:26
    one is that main is never called so
  • 38:24 - 38:29
    let's start off with fixing that so
  • 38:26 - 38:32
    here's how I would make this change and
  • 38:29 - 38:34
    notice how few keystrokes this requires
  • 38:32 - 38:38
    capital G means go to the bottom of the
  • 38:34 - 38:40
    file o opens a new line below and now I
  • 38:38 - 38:45
    can just type in stuff so I'm an insert
  • 38:40 - 38:47
    mode okay so I've typed in whatever
  • 38:45 - 38:50
    change I want to make escape to go back
  • 38:47 - 38:54
    to normal mode if I do : W so command
  • 38:50 - 38:55
    mode right let me go back here okay now
  • 38:54 - 38:57
    at least my program prints something
  • 38:55 - 38:59
    when I run it another issue with this
  • 38:57 - 39:03
    program is that it starts at 0 instead
  • 38:59 - 39:05
    of 1 so let's go fix that so I want to
  • 39:03 - 39:07
    go over to this range whoops this range
  • 39:05 - 39:08
    thing and it shouldn't be going from 0
  • 39:07 - 39:11
    to limit it should be going from 1 to
  • 39:08 - 39:13
    limit plus 1 1 command which I didn't
  • 39:11 - 39:16
    show you about is how you search in vim
  • 39:13 - 39:16
    so you press forward slash
  • 39:17 - 39:22
    to close this and restart it if you
  • 39:19 - 39:25
    press forward slash it starts search so
  • 39:22 - 39:26
    if I type in range enter my cursor goes
  • 39:25 - 39:28
    from wherever it was before to the first
  • 39:26 - 39:29
    instance of range it found so it's a
  • 39:28 - 39:32
    really efficient way of moving where I
  • 39:29 - 39:34
    want to move WW to move forward two
  • 39:32 - 39:36
    words I to go into insert mode add the
  • 39:34 - 39:38
    one comma space escape I'm back in
  • 39:36 - 39:40
    normal mode this is a very common
  • 39:38 - 39:42
    pattern in vim you stay in normal mode
  • 39:40 - 39:43
    you go somewhere you go into insert mode
  • 39:42 - 39:45
    you make a tiny change and you jump
  • 39:43 - 39:46
    right back to normal mode like normal
  • 39:45 - 39:49
    mode is home and that's where you should
  • 39:46 - 39:51
    be most of the time I also want to add a
  • 39:49 - 39:55
    plus one so e to go to the end of this
  • 39:51 - 39:58
    word a for a pend plus one escape
  • 39:55 - 40:01
    alright fix that problem and other issue
  • 39:58 - 40:03
    is that this program prints fizz for
  • 40:01 - 40:06
    both divisible by three and five so
  • 40:03 - 40:08
    let's fix that slash fizz searches for
  • 40:06 - 40:12
    fizz been oppressed and it goes to the
  • 40:08 - 40:14
    next match see I press E I quote changes
  • 40:12 - 40:16
    what's inside the quote so it's deleted
  • 40:14 - 40:17
    the fizz and put me in insert mode right
  • 40:16 - 40:19
    in between those two quotes and I can
  • 40:17 - 40:23
    type in whatever I want
  • 40:19 - 40:27
    escape to go back to normal mode so
  • 40:23 - 40:29
    great I've fixed that particular problem
  • 40:27 - 40:32
    another problem with this program is
  • 40:29 - 40:38
    that it prints fizz and Buzz on separate
  • 40:32 - 40:42
    lines for multiples of 15 so let's let's
  • 40:38 - 40:43
    go and fix that let me go down to this
  • 40:42 - 40:45
    line here
  • 40:43 - 40:46
    one way I can don't actually worry about
  • 40:45 - 40:47
    like the actual contents of this program
  • 40:46 - 40:49
    like this some stupid program that
  • 40:47 - 40:51
    doesn't matter pay attention to what
  • 40:49 - 40:52
    keys I'm pressing in vim that allow me
  • 40:51 - 40:55
    to make changes to this program really
  • 40:52 - 40:57
    efficiently so my cursor is on this line
  • 40:55 - 40:59
    i press dollar to go to the end of this
  • 40:57 - 41:01
    line i for insert mode okay and i'm
  • 40:59 - 41:03
    typing some stuff escape to go back to
  • 41:01 - 41:07
    normal mode now I want to make the same
  • 41:03 - 41:12
    change the print below look at this JJ
  • 41:07 - 41:13
    dot so what dot dozen vim is it repeats
  • 41:12 - 41:16
    the previous editing command that was
  • 41:13 - 41:18
    made and so this is a really nice way of
  • 41:16 - 41:20
    doing repetitive tasks without typing
  • 41:18 - 41:22
    the same thing over and over again so in
  • 41:20 - 41:25
    that particular case that inserted comma
  • 41:22 - 41:27
    end quote and so it applied the same
  • 41:25 - 41:30
    thing on this line when I press dot and
  • 41:27 - 41:31
    then when I guess one final part of this
  • 41:30 - 41:33
    demo is
  • 41:31 - 41:35
    we will fix the issue that this program
  • 41:33 - 41:36
    maybe should take a command-line
  • 41:35 - 41:39
    argument instead of having this
  • 41:36 - 41:40
    hard-coded 10 down here so how do we do
  • 41:39 - 41:43
    that I'll press GG to go to the top
  • 41:40 - 41:44
    capital o so now I've opened a line
  • 41:43 - 41:47
    above and I'm going to type in some text
  • 41:44 - 41:50
    like imports this enter escape to go
  • 41:47 - 41:52
    back to normal mode and then I want to
  • 41:50 - 41:55
    go down to where this 10 is so slash 10
  • 41:52 - 41:58
    makes me jump straight down there CI
  • 41:55 - 42:00
    pren to edit what's inside the
  • 41:58 - 42:02
    parentheses and now I can type in like
  • 42:00 - 42:07
    whatever thing I need to type in here
  • 42:02 - 42:10
    and then once I've done this my program
  • 42:07 - 42:11
    does fizzbuzz correctly I think I missed
  • 42:10 - 42:12
    one change I wanted to make but it
  • 42:11 - 42:15
    doesn't matter this demonstrates that
  • 42:12 - 42:17
    you can make lots of changes really fast
  • 42:15 - 42:23
    so any questions about this demo or the
  • 42:17 - 42:28
    overall idea we've been talking about ok
  • 42:23 - 42:30
    so this will be covered Tuesday so the
  • 42:28 - 42:32
    kind of outside environment I'm running
  • 42:30 - 42:34
    vim on the left and my shell on the
  • 42:32 - 42:39
    right and then this is team ox on the
  • 42:34 - 42:40
    outside one variant of that question
  • 42:39 - 42:42
    might be like how do you switch between
  • 42:40 - 42:43
    different vim windows and you can see
  • 42:42 - 42:44
    the lecture notes for that but there's a
  • 42:43 - 42:46
    key binding for that so if you have the
  • 42:44 - 42:50
    same window open or multiple things open
  • 42:46 - 42:50
    there's a way of doing that question ah
  • 42:51 - 42:57
    good question so delete takes a motion
  • 42:55 - 42:58
    and then removes those contents but
  • 42:57 - 43:00
    keeps you in normal mode so you can keep
  • 42:58 - 43:02
    just moving around in a file what change
  • 43:00 - 43:04
    does is very similar to delete it takes
  • 43:02 - 43:06
    motions and treats them in the same way
  • 43:04 - 43:08
    deletes those contents but then puts you
  • 43:06 - 43:11
    in insert mode and so it saves you from
  • 43:08 - 43:13
    typing one extra keystroke so if I'm
  • 43:11 - 43:16
    here for example I want to delete main
  • 43:13 - 43:18
    DW deletes a word but now if I press
  • 43:16 - 43:22
    whatever key likes I press J it just
  • 43:18 - 43:23
    moved me down if I undo that do cw4
  • 43:22 - 43:25
    change a word now it's actually put me
  • 43:23 - 43:29
    into insert mode and I can type in
  • 43:25 - 43:32
    whatever I want it to insert so DWI is
  • 43:29 - 43:34
    the same thing as CW but it saves a
  • 43:32 - 43:35
    keystroke one thing we've linked in the
  • 43:34 - 43:37
    resources is something called vim golf
  • 43:35 - 43:40
    basically people have set up a game
  • 43:37 - 43:41
    online where you can get an editing task
  • 43:40 - 43:44
    and try to figure out the minimal number
  • 43:41 - 43:44
    of keystrokes necessary to complete that
  • 43:44 - 43:46
    editing
  • 43:44 - 43:47
    it's actually really addictive so I'd
  • 43:46 - 43:53
    only suggest going on their chest and
  • 43:47 - 44:00
    script time I think I saw a hand for
  • 43:53 - 44:02
    another question yeah uh period yeah one
  • 44:00 - 44:06
    of the most useful of em commands good
  • 44:02 - 44:06
    question any other questions
  • 44:07 - 44:13
    cool so I think we have about five
  • 44:11 - 44:15
    minutes left and I'm gonna briefly talk
  • 44:13 - 44:16
    about a thing that's also covered in
  • 44:15 - 44:19
    detail in the notes so make sure you
  • 44:16 - 44:22
    look at the notes for this so vim is a
  • 44:19 - 44:24
    programmers text editor and so of course
  • 44:22 - 44:26
    it's highly programmable not only
  • 44:24 - 44:28
    through its interface that's a
  • 44:26 - 44:29
    programming language but also a couple
  • 44:28 - 44:31
    of different ways there's lots of
  • 44:29 - 44:33
    settings that you can tweak to match
  • 44:31 - 44:35
    your preferences and you can also
  • 44:33 - 44:38
    install plugins for them that do all
  • 44:35 - 44:40
    sorts of useful stuff so the way vim is
  • 44:38 - 44:43
    configured is through a file on disk
  • 44:40 - 44:45
    called vim RC and you'll see this is a
  • 44:43 - 44:47
    common pattern in a lot of shell based
  • 44:45 - 44:49
    tools there'll be a plain text file that
  • 44:47 - 44:51
    configures how the Tool Works and so if
  • 44:49 - 44:54
    I edit this file and it may or may not
  • 44:51 - 44:56
    exist on your machine yet but I've
  • 44:54 - 44:58
    downloaded the we've created a kind of
  • 44:56 - 44:59
    default vim RC for you and linked it on
  • 44:58 - 45:02
    the course website so you can start with
  • 44:59 - 45:05
    that one if I do vim tilde slash boom RC
  • 45:02 - 45:07
    I can see here a bunch of comments and
  • 45:05 - 45:09
    then particular commands like by default
  • 45:07 - 45:11
    we want syntax highlighting on and we
  • 45:09 - 45:13
    want line numbers if we didn't do some
  • 45:11 - 45:15
    of these things like let me remove the
  • 45:13 - 45:16
    stuff that sets line numbers if I remove
  • 45:15 - 45:18
    those configurations and relaunch vim
  • 45:16 - 45:21
    notice that I no longer have line
  • 45:18 - 45:23
    numbers on the left but yeah so in short
  • 45:21 - 45:26
    there's a lot of stuff you can configure
  • 45:23 - 45:29
    with them we've given you a very basic
  • 45:26 - 45:30
    configuration that tries to like remove
  • 45:29 - 45:32
    some of the kind of weird behavior
  • 45:30 - 45:33
    that's on by default in vim but we don't
  • 45:32 - 45:36
    really try to enforce too many of our
  • 45:33 - 45:37
    other opinions on you but of course like
  • 45:36 - 45:39
    the three of us used them a lot and we
  • 45:37 - 45:41
    have heavily customized VMR C's so we've
  • 45:39 - 45:42
    linked to our personal configurations
  • 45:41 - 45:45
    too if you want to take anything from
  • 45:42 - 45:46
    that and also like thousands or like
  • 45:45 - 45:48
    millions of people share their var C's
  • 45:46 - 45:48
    on github so there's lots of places to
  • 45:48 - 45:50
    look for inspiration
  • 45:48 - 45:53
    there's also cool blog posts on this
  • 45:50 - 45:55
    topic another thing you can do in vim is
  • 45:53 - 45:57
    you can extend it with plugins that do
  • 45:55 - 45:58
    all sorts of useful things this lets you
  • 45:57 - 46:00
    do things like fuzzy file
  • 45:58 - 46:01
    finding which a lot of text editors come
  • 46:00 - 46:03
    with by default so you can get like a
  • 46:01 - 46:05
    pop-up window you can type in a name of
  • 46:03 - 46:07
    a file or approximately the name of a
  • 46:05 - 46:08
    file and find it very quickly or there
  • 46:07 - 46:11
    are things that show you like
  • 46:08 - 46:15
    visualizations of undo history there are
  • 46:11 - 46:16
    things that show you like file explorers
  • 46:15 - 46:18
    things like that so we've linked to a
  • 46:16 - 46:21
    couple of our favorite plugins on the
  • 46:18 - 46:22
    course website and so I highly recommend
  • 46:21 - 46:23
    becoming familiar with how to install a
  • 46:22 - 46:25
    plug-in because it takes like three
  • 46:23 - 46:30
    seconds and some of them are really cool
  • 46:25 - 46:32
    and then finally the last topic I'll
  • 46:30 - 46:35
    briefly mention before we finish today's
  • 46:32 - 46:37
    lecture is vim mode and other programs
  • 46:35 - 46:39
    so turns out that a lot of programmers
  • 46:37 - 46:41
    we're really excited about VIMS
  • 46:39 - 46:43
    interface and so they've implemented
  • 46:41 - 46:45
    similar functionality and other tools
  • 46:43 - 46:48
    for example like I've configured my
  • 46:45 - 46:50
    Python repple to run in vim mode so I
  • 46:48 - 46:52
    can like type in stuff here and if I
  • 46:50 - 46:53
    press escape now I'm in normal mode in
  • 46:52 - 46:55
    my Python repple and I can like move
  • 46:53 - 46:58
    back and forth and like press X here
  • 46:55 - 47:02
    delete a thing like CW change a word and
  • 46:58 - 47:03
    do all those good things and it's not
  • 47:02 - 47:06
    just the Python repple like I have my
  • 47:03 - 47:08
    terminal behaving this way too so like I
  • 47:06 - 47:10
    can type in whatever I want here and
  • 47:08 - 47:11
    like escape and I'm in normal mode I can
  • 47:10 - 47:13
    go here and like go into visual mode
  • 47:11 - 47:16
    inside my terminal and like select
  • 47:13 - 47:20
    blocks of text press tilde to change the
  • 47:16 - 47:22
    case whatever so we've linked sir like
  • 47:20 - 47:26
    how exactly you can enable vim mode for
  • 47:22 - 47:28
    like bash z shell fish a lot of read
  • 47:26 - 47:29
    line based programs like jupiter
  • 47:28 - 47:30
    notebook a whole bunch of other things
  • 47:29 - 47:32
    and if it's not another place you can
  • 47:30 - 47:34
    probably find it by googling it because
  • 47:32 - 47:36
    a lot of people like to have this sort
  • 47:34 - 47:37
    of functionality and if you're really
  • 47:36 - 47:39
    gonna like commit to learning them I
  • 47:37 - 47:41
    think it's valuable to enable this sort
  • 47:39 - 47:43
    of like vim emulation mode in every tool
  • 47:41 - 47:45
    you use is like one or like make you
  • 47:43 - 47:47
    learn the tool a lot better and to once
  • 47:45 - 47:48
    you become good at vim like those skills
  • 47:47 - 47:53
    will now transfer to all your other
  • 47:48 - 47:55
    tools you use okay so I think that's it
  • 47:53 - 47:57
    for our rapid introduction to them
  • 47:55 - 47:58
    there's some other neat material that we
  • 47:57 - 48:00
    weren't able to fit in today's lecture
  • 47:58 - 48:01
    but it's in the lecture notes and then
  • 48:00 - 48:03
    finally I highly recommend going through
  • 48:01 - 48:05
    the exercises for today like at least
  • 48:03 - 48:07
    for me personally I think spending time
  • 48:05 - 48:09
    learning my text editor has been like
  • 48:07 - 48:10
    the most beneficial thing out of like
  • 48:09 - 48:12
    the kinds of things we're teaching in
  • 48:10 - 48:14
    this class
  • 48:12 - 48:16
    so yeah that's it for today's lecture
  • 48:14 - 48:18
    and we'll see you tomorrow
  • 48:16 - 48:20
    note that we've changed tomorrow's
  • 48:18 - 48:22
    lecture to data wrangling Thursday and
  • 48:20 - 48:24
    Tuesday lectures are now switched this
  • 48:22 - 48:25
    is reflected on the course website in
  • 48:24 - 48:28
    case anybody was going to come to one
  • 48:25 - 48:28
    but not the other
Title:
Lecture 3: Editors (vim) (2020)
Description:

more » « less
Video Language:
English
Duration:
48:27

English subtitles

Revisions