Vim As Your Editor - Introduction
Summary
TLDRThe Primogen introduces a multi-part series on mastering Vim, a highly efficient text editor. With a focus on Vim motions, the video guides viewers from novice to expert level, emphasizing the importance of understanding Vim's modes: normal, insert, visual, and command. The tutorial covers basic cursor movements, efficient text navigation, and commands like delete and yank. The speaker encourages practice and offers resources like a VimRC video and games to build muscle memory, aiming to transform text editing into a fast, intuitive process.
Takeaways
- ๐ The speaker has been using Vim for 10 years and aims to guide viewers from novice to expert level in a multi-part series.
- ๐ The series will focus on Vim motions and navigating within Vim, emphasizing the efficiency of these motions across various programming environments.
- ๐ The speaker advises against starting with Vim if you have no prior experience, recommending the use of Vim modes or plugins in existing editors first.
- ๐ค Learning every single key in Vim is discouraged; instead, the speaker suggests adopting a more streamlined approach to learning.
- ๐ Vim operates in different modes: Normal, Insert, Visual, and Command, with Normal mode being the starting point for cursor movement.
- โก๏ธ Basic cursor movements in Vim are done using 'h', 'j', 'k', 'l', with 'w' and 'b' allowing word-based navigation.
- ๐ฎ Neovim users can practice motions with a built-in game that helps build muscle memory for efficient cursor movement.
- ๐ข Vim motions can be augmented with counts, allowing for repeated actions, such as '8k' to move up eight lines.
- โ๏ธ The 'D' command in Vim is used for deletion, and can be combined with motions for more extensive deletions, like 'D3j'.
- โฉ๏ธ Insert mode in Vim allows for regular typing, with 'a' and 'I' being useful commands for moving the cursor within the text.
- ๐ Visual mode in Vim is used for selecting text with motions, and 'y' (yank) and 'p' (paste) are key commands for copying and pasting.
- ๐ Yanking and deleting in Vim use the same buffer, meaning pasting with 'p' after a deletion will recover the deleted text.
Q & A
What is the main focus of the Primogen's series on Vim?
-The main focus of Primogen's series is to guide viewers from being complete beginners in Vim to becoming experts, focusing on mastering Vim motions and navigating within Vim.
Why does Primogen recommend using Vim motions even if one is not using Vim as their primary editor?
-Primogen recommends using Vim motions because they are extremely efficient and available in many popular editors like IntelliJ, Sublime, and VS Code, improving overall navigation and editing speed.
What does Primogen suggest as a starting point for someone completely new to Vim?
-Primogen suggests that beginners should start by using Vim mode or Vim plugins in their current editor of choice, such as VS Code or IntelliJ, to get familiar with the motions before diving into Vim itself.
What are the four modes in Vim that the script mentions?
-The four modes mentioned in the script are Normal mode, Insert mode, Visual mode, and Command mode.
What is the difference between 'yank' and 'delete' in Vim, as explained in the script?
-In Vim, 'yank' copies the selected text to the clipboard, while 'delete' removes the text and also places it in a buffer from where it can be pasted later. Both operations use the same buffer.
How can one undo and redo actions in Vim according to the script?
-In Vim, one can undo actions by pressing 'U' and redo them by pressing 'Ctrl R'.
What is the significance of the 'hjkl' keys in Vim as discussed in the script?
-The 'hjkl' keys are fundamental movements in Vim, representing left (h), down (j), up (k), and right (l), allowing for cursor navigation in Normal mode.
What is the purpose of the 'W' and 'B' motions in Vim?
-The 'W' motion in Vim moves the cursor forward by words, similar to holding the option key and pressing the arrow key on a Mac. The 'B' motion moves the cursor backward by words.
How can one navigate more efficiently in Vim according to the script?
-The script suggests using motions with counts, such as '8k' to move up eight lines or '16j' to move down sixteen lines, for more efficient navigation.
What is the role of the 'visual mode' in Vim as described in the script?
-Visual mode in Vim allows the user to highlight text using motions, after which they can perform actions like yanking (copying) and pasting.
What does Primogen suggest for learning Vim efficiently?
-Primogen suggests learning Vim motions first and mastering them until they become second nature, before moving on to more advanced features of Vim.
How does Primogen describe the learning experience of Vim for beginners?
-Primogen describes the learning experience of Vim for beginners as the hardest part, especially getting used to the Vim paradigm shift from mouse-oriented control to a more keyboard-centric motion system.
What is the 'relative line numbers' feature in Vim mentioned by Primogen and how does it help?
-Relative line numbers in Vim shows the distance of lines from the current line, which helps in quickly jumping to different parts of the document without having to count lines manually.
What is the significance of the 'dd' command in Vim as explained in the script?
-The 'dd' command in Vim deletes the current line. It can be combined with motions to delete a range of text, such as '3j' to delete the current line plus the next three lines.
How does Primogen recommend practicing Vim motions?
-Primogen recommends using a game-like approach, such as the 'vim be good' game in Neovim, to practice Vim motions and build muscle memory in a fun and engaging way.
Outlines
๐ป Introduction to Vim Mastery Series
The speaker, Primagen, introduces a multi-part series aimed at transforming beginners into Vim experts. They emphasize the distinction between Vim as a program and Vim motions, the latter being highly efficient and available in various editors. Primagen encourages starting with Vim motions in familiar editors before diving into Vim itself, which requires customization for optimal use. The series focuses on mastering Vim motions and navigating within Vim. They also recommend using Vim mode in existing editors and provide a link to a video on Vim RC for further learning.
๐ Understanding Vim Modes and Basic Movements
Primagen explains the four essential modes in Vim: normal, insert, visual, and command mode. They detail the functions of each mode, with a focus on normal mode for cursor movement. The speaker introduces fundamental cursor movements using 'h', 'j', 'k', and 'l', and recommends becoming proficient with these. They also touch on the concept of Vim games to enhance learning and muscle memory, and briefly mention advanced movements like 'W' and 'B' for word-based navigation.
๐ Enhancing Vim Efficiency with Motions and Commands
The speaker demonstrates how to augment Vim motions with counts for repeated actions, such as moving the cursor up or down multiple lines. They introduce the 'D' command for deleting text, which can be combined with motions for more complex operations like deleting multiple lines or words. Primagen also covers undo and redo commands, and transitions into discussing insert mode, emphasizing the use of 'a' to append text and the various ways to exit insert mode. The paragraph concludes with a teaser for upcoming content on visual mode and yank/paste operations.
โ๏ธ Mastering Visual Mode and Text Manipulation
Primagen delves into visual mode, explaining how to select text using 'V' and 'Shift-V' for character-wise and line-wise selection, respectively. They show how to yank and paste text in visual mode, highlighting the difference between pasting in character-wise and line-wise contexts. The speaker also discusses the relationship between yanking, deleting, and the paste buffer, noting that pasting with 'p' can replace the current selection with previously deleted content. They conclude by emphasizing the importance of mastering these fundamental motions and commands as a stepping stone to more advanced Vim techniques.
Mindmap
Keywords
๐กVim
๐กVim Motions
๐กNormal Mode
๐กInsert Mode
๐กVisual Mode
๐กCommand Mode
๐กHJKL
๐กVimrc
๐กYank and Paste
๐กDelete
๐กUndo and Redo
๐กRelative Line Numbers
Highlights
Introduction to a multi-part series aimed at transforming users from Vim novices to experts.
Differentiation between Vim the program and Vim the Motions, emphasizing the efficiency of Vim motions across various editors.
Personal preference for configuring Vim to suit individual needs for optimal utility.
Recommendation to start learning Vim motions with existing editors before transitioning to Vim itself.
The importance of not trying to learn every key in Vim at once, but rather adopting a more gradual approach.
Highlighting the challenge of transitioning from mouse-oriented control to Vim's home row motion-centric paradigm.
Explanation of Vim's modal editing concept, focusing on Normal, Insert, Visual, and Command modes.
Basic cursor movement techniques in Normal mode using hjkl keys.
Introduction of Vim's game for practicing cursor movements and building muscle memory.
The concept of motion commands in Vim, including word hopping with 'W' and walking backwards with 'B'.
Augmenting motion commands with counts for multiple actions, such as 8K to jump up eight lines.
Combining the 'D' command with motion to delete text, like D3J to delete three lines down.
Undo and redo functionalities in Vim with the 'U' and Ctrl+R (or 'Ctrl+Y') commands.
Entering Insert mode with 'I' and the various ways to exit it, including Escape and Ctrl+[.
The use of 'a' to append text after the cursor and its frequent utility in day-to-day editing.
Visual mode's functionality for selecting text using motions and performing yank and paste operations.
Differences between using yank in Visual mode and yanking without selection, and the implications for pasting.
The peculiar behavior of 'P' to paste the last deleted content, showcasing Vim's unique buffer system.
Encouragement to practice Vim motions until they become second nature for efficient and fast editing.
The series' aim to demystify Vim and make it feel like a game with smooth and fast editing capabilities.
Transcripts
my name is the primagen and I've been
using Vim for about 10 years and I
wanted to take the time to build a
series in which could lead you from
someone who doesn't know anything about
Vim to someone who could become an
expert at using Vim now this is going to
be a multi-part series in which each
One's Gonna add to the next one and
it'll get you progressively faster as
you go and I do want to make a
separation right away there is vim the
program and Vim the Motions now Vim
motions I don't understand why anyone
who is programming does not use those
those are extremely efficient and
they're very well done and they're
available in IntelliJ Sublime Even Adam
vs code anything you want to use they
have them but Vim the editor I
understand why that may not be as
appealing you have to kind of want to be
able to configure and create your own
environment to exactly your own needs
for them to be super useful and so this
a few part series is going to be focused
on making you awesome at Vim motions and
navigating some things within Vim I'll
try to separate them out so if you're
just not interested in Vim itself that's
how okay but if you are interested more
in using Vim I have a video on your Vim
RC which you can go check out right now
links down in the description and as you
pass by that like button give it like a
little bit of coconut oil appreciate it
all right so right away I do not think
that you should start out in Vim if you
have no familiarity with Vim I really do
think you should continue to use vs code
if that's what you're using IntelliJ if
that's what you're using whatever editor
you're currently using use the Vim mode
or the Vim plugin now I think one of the
big mistakes when learning Vim is that
you try to learn every single key
possible all the different shortcuts and
then you're just sitting sitting there
just like mentally grinding to try to
find the most optimal one in every
single moment that sounds exhausting so
that's why I just took a much different
approach myself to learning it and I'm
gonna try to give you that exact same
approach that I took 10 years ago
alright so one last kind of preface this
will be the hardest of all the videos
because the getting started is the
hardest because you're going from a
paradigm of using the mouse and being
much more kind of click and control
oriented into using something like Vim
which is just much more home row motion
Centric now I know that a lot of you are
probably using vs code I hear if you hit
the Subscribe button right now it
actually makes learning easier go check
the comments people will say that trust
me it makes it easier all right so the
first thing you need to know about Vim
is that it's a model editor whether
you're using it in vs code or Vim itself
you are in various modes and there's
four modes that you really need to be
concerned about first off the mode that
you're in right away is normal mode it
just means that I can move my cursor
around second mode is insert mode you
can see it right down here says insert
that just means I can type like a
regular editor hit all the enters do
everything that it will it'll try to
Auto indent and do the best job it can
third is visual mode you can see right
down here again I'm in visual line mode
as I move it's kind of like highlighting
with your cursor and of course the
fourth mode is command mode if I press
colon you'll notice right here that a
colon appears and my cursor actually
appears on this line I can now type out
some commands a command you should know
is W colon W enter will save the current
file colon WQ will attempt to quit now I
know I ruined all the memes but guess
what the memes are still funny I
actually still like him 10 years later I
still enjoy can't quit Vim memes all
right so let's go over each of the modes
in detail all right so normal mode the
mode you can move your cursor around the
most foundational movements you need to
know is j and k k will obviously go
upwards J will go downwards I have my
keystrokes right here so you can watch
them happen L is going to go this way
and H is going to go this way now these
are the most fundamental movements I do
recommend getting pretty dang good with
them now if you have neovim I actually
built the game for the zigzags thing so
if you do command mode Vim be good you
will get a game if you navigate down
with your JS all the way down to hjk and
L press d d to delete that line it will
start a game for you where you can
actually walk around to each one of
these and then press X to delete it X on
the X and this right here will just help
you get good and just kind of build that
muscle memory in super quick without
making it feel so boring as trying to
use the text editing program but instead
you got a little quick game really just
helps you make that connection with
those keys if you don't know how to do a
plug-in again I have that vimrc video
which I have linked down below but
you'll quickly realize that hjk L is
just not enough right that H and L is
really inconvenient you just like hold
it and slowly go over that would just
melt my mind now I told you Vim is fast
it is smooth it blows people away when
you see someone who is really good at it
use it so obviously L can l and H can't
be the last of your movements so the
last two I really wanted to show you was
W which hops over by word something
equivalent of like holding option I
think on Mac and pressing the arrow key
and B the opposite walks backwards so
those movements are called motion
emotion is anything that moves the
cursor all right so I wanted to go over
the anatomy of emotion so right now all
we've been focusing on is this part
right here hjklwb
those are motions they move the cursor
but did you know that you can kind of
augment them meaning that if we add a
count to it it'll be performed multiple
times so check this out so you can see
about eight lines up there is a to-do
line right up there which if I press 8K
I will jump my cursor eight times up to
that to do line if I want to go back say
all the way down to the return statement
16 lines down I can go 1 6 J you can see
right here I did 16j and my cursor
landed on the return statement right
there yes you're probably impressed with
my Vanna White level pointing skills I
know you can't train it you're born with
it again if you have been be good uh I
did do another one of these games right
down here so if you go all the way down
to relative you turn on relative line
numbers inside your vmrc you can do you
know six down you can just practice the
deleting game so that you can get good
at jumping around while deleting
relative line numbers have helped me in
enormous amounts so I highly recommend
you getting used to jumping around with
relative line numbers obviously counts
work with all the other motions so I can
technically go like 10 L but that'd be
weird or 2B also that would be weird
that sounds like way too much overhead
to try to count how many jumps you have
I would not use that as a way to move
around in Vim all right so let's add a
little bit more let's talk about
commands you can do I want to focus
right now just on the D command d stands
for delete meaning that if I wanted to
delete a line I can press d d that will
just simply delete a singular line I
press U to undo that delete I can press
Ctrl R to redo my previous action so U
is like control Z control R is like
control y D's can be used with motion
just like I said we can do a command
account and a motion so jumping back
here if I'm on this line right here and
I want to delete all the way down to the
return statement but not the return
statement what I can do is I can go D 3
J I have deleted my current line plus
three down below me that means I can
also go delete word that's how you would
delete a single word delete two word you
could delete two two words if you really
want to again I don't do the whole two
with words or back or any of those that
means you can do DB and delete backwards
so D is a command you can mix with a
motion hopefully you're starting to
understand and you're happy that I kind
of went over the anatomy of emotion
because this should start making sense
okay I can move the cursor and I can
delete move the cursor all right so
let's talk about insert mode now first
off I want you to look at where my
cursor is right up here now this cursor
of course is fat it has you know care it
covers an entire character it's just
something I've gotten used to uh some
people when they go into insert mode
their cursors can become thin I never
like that so don't be taken back by this
as you watch me go but if I press I I go
on the left side of my cursor for insert
mode so as you can see I pressed I to go
into insert mode and then I just started
typing and boom these characters come
here now we can leave insert mode by
pressing escape you can also press Ctrl
C and you can also press Ctrl Open
Bracket control Open Bracket and Escape
are the same control C does have some
minor variations to it mostly in visual
block mode that cause some weirdness to
it so you got to know which one you like
alright so you can press U to undo of
course now if I press a you'll notice
that it moves my cursor but I'm in
insert mode so now as I type I'm on the
other side of the zero now you're
thinking okay when would you actually do
you actually ever need that you'd be
surprised at how often pressing a to
move forward like how often you actually
use that a and I become something that
you should just use all the time it's
very very surprising so I'm going to
leave insert mode undo it there we go
there's a bunch of other ways to enter
into insert mode but I think you should
really just get used to that right now
we're about few options even if it's
inconvenient you need to learn the
basics and move fast all right so let's
move on to the last part visual mode so
this one I'm actually going to show you
how to use yank and paste in visual mode
so visual mode has two primary ways
you're going to use it if you press V
you'll go into visual mode down here
that means I can use any of the Motions
that I've learned so far so I can press
W and you'll notice that it's like
highlighting as it's go as it's going
this is effectively like using your
mouse and dragging it and highlighting a
region at this point I could copy and
paste so normally you'd press probably
Ctrl C or command C if you're on one of
those fills drinking coffee Max
but in Vim you just press y y Yanks it
now if I press p i will paste it as you
can see I paste it now notice something
it's not giving me a new line it's
facing the exact contents of what I
yanked so let's undo it with you undo
undo undo and this time let's use shift
V we'll go into visual line mode now
when I yank this if I paste it I
actually get that new line at the end a
little bit more convenient so you kind
of got to know which one you want to do
let's do a little bit of comboing so
what I can do is I can actually
highlight I can yank it I can jump down
here and I can highlight this and I can
paste it so you can paste over a
highlighted region but I'm going to show
you something that's a little bit weird
what do you think happens if I press P
now well I get the last thing I deleted
so that means if you press d d and
delete a line and you press P you
actually paste the last thing you
deleted so yanking and deleting goes to
the same buffer and again if you
highlight a bunch of stuff and you paste
it you'll delete all of that at and then
paste over it with the contents you have
in your paste buffer and now when I
press p i get all the previous things I
deleted and
you can use yanking just by itself so I
can press y y you don't have to
highlight first to use yanking now if
you remember the anatomy of emotion I
did show you that you can do a command
account and the motion so I can do yank
say five and down I just yanked all the
way to this offset line right here so
now when I press P you'll notice I got
those five lines and I was able to paste
them all which means I can also do the
exact same thing with d d5j and I can
paste the things that I just got done
deleting down below now I really wanted
to stress this and I wanted to make sure
you had the time to hear me on this one
which is this is going to be the hardest
of all the lessons if you are new to Vim
this is the hardest part learning how to
do hjk L learning how to do relative
jumps kind of getting your feet wet with
that Vim RC which is still linked down
below like it's just a lot of
information it is very difficult so if
you're using vs code don't feel bad just
keep using vs code that's what I did
when I was gonna use Vim as my editor I
actually started It Off by using idea
Vim the IntelliJ plug and I used that
for years I got really good at the
motions and then moved over so once you
feel like you've really mastered these
motions and they don't feel hard for you
to think about they feel very second
nature you gotta move on to the next
part of this series I don't know how
many videos this series is going to be
somewhere between three to five but I am
hoping to give you a very detailed way
to make Vim as your editor and mostly I
just hope that you feel encouraged
because you know what when I use Vim as
my editor it almost feels like a game
because I have all these combos that I'm
doing I can move really really fast and
I have the ability to do a lot without
having to think too much I really do
like the idea of making everything
second nature to the point where you
don't think about editing the text you
just edit it really fast and that's the
coconut oil goodness that I'm trying to
give you okay if you want to be smooth
and sliding around you just gotta Master
the fundamentals okay practice for a
week and come back for part two the name
is the primogen
5.0 / 5 (0 votes)