Home Getting Started with Vim
Post
Cancel

Getting Started with Vim

How to Quit?

Because Vim is a modal editor, the first question to answer is how to close it. It’s kind of a meme at this point. However you can close vim by pressing “:q” followed by the enter key. This only works if you are in “Normal” mode. Vim has 4 primary modes: Normal, Insert, Visual, and Command. Normal is the default mode and the one that you should spend the most time in. Insert is the mode where the keyboard works like normal and inserts text into your file. Visual is the mode where you can highlight text to copy or delete the highlighted content. Command is the mode where you either give Vim commands or the environment. By pressing the colon while in normal mode, you switch to command mode, and the “q” in the original example is a shortcut for the quit command.

Basic Navigation

While keeping within normal mode, you can move around the file without the arrow keys. The replication of the arrow keys are ‘h’, ‘j’, ‘k’, and ‘l’ which are left, down, up, and right respectively. However that’s not very different from a normal editor. So what gives? This is merely step one on the way to a fully, and I truly mean fully, customizable text editor.

However lets go to step 2 with some more movement commands. You can press ‘w’ to jump the cursor forward by a word. Then there’s ‘b’ to jump the cursor back by a word. Furthermore, you can search by typing ‘/’ followed by the text that you want to search for. Then press enter to jump to the first instance below the cursor’s current location. Then you can press ‘/’ and enter to jump to the next one.

Insert Mode

With Insert mode, there are alot of different ways to get into it, but the basic way to get into Insert mode press ‘i’. While in insert mode, you can type into your file like you normally would. Press the escape key to get back to normal mode. I personally end up remapping escape to my caps lock key on my computers for this reason alone. I also never use caps lock, so it doesn’t tend to bother me much. Some other ways to get into Insert mode are by using ‘A’ or ‘I’. These allow you to go into insert mode at the end or beginning of the current line respectively. There are many other ways to get into and out of Insert mode. These will get you started until you get more muscle memory.

Visual Mode

Visual mode isn’t something that I use very often, but it is great when you need it. I’m still relatively new with vim, as I’m been using it on and off for about 4 years now. However Visual mode allows you to highlight text. Once highlighted, you can copy, or delete it. To delete, you’ll need to press the ‘d’ key, and to copy you’ll need to press the ‘y’ key. Then to paste, you can press the ‘p’ key. However if you have multiple lines selected, you can press shift + ‘i’ and get into an insert mode that will apply you edits to all selected lines.

Conclusion

This is only the beginning of your journey with Vim should you choose to undergo it. While it takes time and requires more than a fair bit of effort to develop the muscle memory to get up to speed, it is well worth it. As the old saying goes, anything worth having takes time and effort to obtain.

Vim Chart

KeyModeAction
hnormalmove the cursor left
lnormalmove the cursor right
jnormalmove the cursor down
knormalmove the cursor up
wnormaljump the cursor forward by a word
bnormaljump the cursor back by a word
inormalenter insert mode at the cursor’s current location
Anormalmove cursor to the end of the line and enter insert mode
Inormalmove cursor to the beginning of the line and enter insert mode
escapeinsert or visualenter normal mode from insert or visual
dnormal or visualdelete character under the cursor or the selected text
yvisualcopy the highlighted text
pnormalpaste the copied text
vnormalenter visual mode at the cursor’s current location
:normalenter command mode, followed by the command that you’d like to run
This post is licensed under CC BY 4.0 by the author.