How To — Vim Beginner Basics

Derrick Gee
6 min readMay 19, 2021

Here are some vim tips that should get you up and running starting from zero knowledge of Vim. Why vim? I personally like it because it’s fast to spawn several vim instances within milliseconds, easy to customize your settings and save it to a single config file use on other computers or even servers, it’s highly extensible, and since most keystrokes are a shortcut; you can become very fast at editing text.

The goal of after reading this is to be able to know how to edit in vim at a slightly faster pace than traditional methods. Hopefully the lists and gifs will be a good reference to learn from, since I’d like to think a majority of people learn better with those than reading a block of text. Assuming familiarity of the terminal, we can open vim with typing in vim in the terminal. If you don’t have vim , then you can search up on how to install it easily with the OS that you currently have. For Windows users, I highly recommend using WSL so that you can use one of the Linux package managers.

Immediately, we see how to exit. Type :q to exit. Here are some common ways to exit:

  • :q — Just quit
  • :q! — Quit without saving
  • :wq — Save and quit
Vim cool

Movement

Okay, so this might be a highly an controversial thing to say, but I think arrow keys are okay to use on a very small keyboard. My current keyboard is a 60%, and the arrow keys are only 2.5 keys away from hjkl. I also have macros on fn+arrow to do specific things because it is easier to do fn+arrow than fn+hjkl . Maybe back in the days of full keyboards, it would have been slow to use arrows over hjkl due to them being several keys apart. I think it’s fine due to the advancement of peripherals in today’s age though. Also, some people in the generation of gamers might feel more comfortable with having their hands more spread apart. With that out of the way, movement in vim can be done with hjkl or up down left right . There will be more movement shortcuts in the modes section below.

Quitting

Modes

Vim has modes you need to enter in order to do specific things. This is the very first concept you need to grasp before using Vim. For the most part, you will normally be in insert or normal mode. My gifs will have a plugin called vim-airline that shows which mode you are in with color codes.

Vim modes

Normal Mode

You can get into this mode by pressing esc , you will also start out in this mode when entering a file. Normal mode makes you not able to edit text directly, and makes your keyboard keys into shortcuts for movement and utility. Some common normal mode shortcuts:

Normal Mode Movement

  • o : Create a newline down, go to that line, and go into insert mode
  • A : Go to end of line and go into insert mode ($ not going into insert mode)
  • I : Go to start of text of line and go into insert mode
  • 0 : Go to start of line
  • w : Move forward a word
  • b : Move back a word
  • W : Move forward a word separated by whitespace
  • B : Move back a word separated by whitespace
  • G : Go to end of file
  • gg : Go to top of file
  • ? : Go to command mode and search for a word in file
  • shift+up/down : Go one page up or down. PgUp/PgDown also does the same. Defaults are ctrl+f/b , but I recommend keybinding these if you are using arrows.
  • 11up/down : Go up or down 11 lines. Can replace 11 with any number, I just find 11 to be the easiest to type. Without arrows: 11j/k .
Moving around quickly

Normal Mode Utility

  • u : Undo once
  • ctrl+r : Redo once
  • dd : Delete (Cut) line
  • yy : Yank (Copy) line
  • p : Paste
Quick utility

Insert Mode

Hit i while in normal mode to get into insert mode. This mode lets you type in the file, and hit esc to return to normal mode. There are a few shortcuts you can use this in this mode, but I like to keep shortcuts to normal mode only as much as possible.

Insert mode

Visual Mode

This mode is like highlighting text on a browser or any highlightable text on an app. Start out in normal mode, and you can enter one of these 3 sub modes (move around with arrows or hjkl):

  • v : Regular visual mode, this is probably the most familiar to most people. It is a similar highlight method to mac or windows, where you can highlight from the cursor forward or backwards.
  • V : Visual Line mode, lets you highlight line by line
  • ctrl+v : Visual block mode, lets you highlight in a block

We can perform normal mode shortcuts once we highlight the text we want:

  • d : Delete (cut) the highlight
  • y : Yank (copy) the highlight

Now we can start to combine some shortcuts we learned in normal mode with visual mode:

  • VG : Highlight from current line to end of file, Vgg to highlight from current line to top of file
  • V11down : Highlight from current line to 10 lines down
Visual Mode
Visual Line Mode
Visual Block Mode

Tips

Normal mode shortcuts have a combination feature that is somewhat intuitive. So a will literally mean ‘a’, as in ‘delete a word’, which is actually a shortcut:

i in a combination stands for ‘in’, so here is ‘deleting in )’:

di” di)

The shortcut combos kind of have a pythonic psuedocode feel to it where you think it might work, and it actually does work when you try it. I think knowing these shortcut combos will greatly boost the speed of your editing, as it is a lot faster the type daw with one hand rather than move your mouse to the word, double click to highlight the word, and then press backspace to delete.

Don’t get discouraged if you are slow at first, that’s just life. The learning curve at first might be a little steep, but it plateaus pretty fast after you get used to it. It is true that the more you learn vim, the less you will know about it. However, thinking and gauging whether you should learn this new editing shortcut/method or not is what will make you competent in vim. In the end, everyone has their own preference on how they like to do things, which is arguably the most important factor when deciding on a text editor. More advanced vim topics might come at a later date.

Like my content? GithubTwitterMediumSupport Me

--

--