Vim
Vim is a powerful text editor used for efficient text and code editing. These notes are used to help me understand Vim and its all its tools.
Vim is really cool because it sort of functions like grammar. Once you learn a few shortcuts and the basics of it, you can combine the commands together to do some really cool and smooth things in the text editor.
The main thing about Vim are the motions. These are ways to move around the text editor without using a mouse.
Vim Modes
Vim has four primary modes:
I will go into more detail of the different modes in their respective pages but I will give a brief overview of each.
Normal Mode
This is where all the vim motions happen and where you'll be spending most of your time. Here is where you can move the cursor around using vims commands.
Visual Mode
I like to think of this as the highlighting mode as if you were using a mouse. Here, you can use motions like normal mode except you highlight as you move the cursor around.
Insert Mode
This is where all the typing gets done and where Vim behaves like a normal editor.
Command Mode
Command mode is used for typing in editor commands like saving or quitting a file. This is a little more advanced so I'll go into more detail in the Command mode page.
Vim Motions
Lets first go over the basics: hjkl
are the primary motions. Here is what all of them do
- h move left
- l move right
- j move down
- k move up
These commands move the cursor around one character at a time.
There are also more advanced commands like
- b move back a word
- w move forward a word
Vim Commands
You can picture Vim as being a command + a number + a motion
.
Some of the most useful commands include
- d delete
- y yank (copy)
- p (paste)
- $ go to end of line
- ^ go to beginning of line
You can combine these commands to do some cool things. Like dd
to delete an entire line, yy
to yank (or copy) an entire line.
As mentioned above, you can do a command + a number + a motion
. So typing d5j
deletes the current line and 4 lines below it. Or y10k
which copies 10 lines above.
One important thing to note is that yanking and deleting go to the same buffer. So deleting a line using dd
and then pressing p
will paste that deleted line.
Some other useful commands using visual mode are shift-v
which enters visual line mode (copies the whole line) so when you copy and paste, it gives you a new line.
Conclusion
Vim has been one of the coolest things I have learned so far and will continue using for the rest of my development career. Continue reading below to dive deeper!