Vim for beginners — zero to hero

As an engineer we can craft our development process, speed and productivity to get where we want to faster.

basic workflow of editing code with vim

How to open a file

vim my-file.text

This simple command in MACOS terminal for instance will open the file “my-file.text” in the terminal itself (to avoid opening external code/text editing softwares like Vscode or sublime) and will allow us to quickly edit our code

How to start edit

Click the letter “i”, once we did you’ll see at the bottom the word “ — — INSERT — — ” and from this point on we can edit the code since we change the mode from “command mode” (default) to “insert mode”.

How to save and quit

In command mode write

:wq

Then enter to execute “write & quit” the file.

Workflow of commands

Let’s go through a flow of work with VIM just to make sure we get the right idea how to edit files. In this flow we’ll create a readme file which is common for many open source projects. We are going to open the project, edit the project then save the changes we apply and check that the changes are saved.

Open file with VIM

In the command line (iterm for example) let’s write the next command to create our README.md file than we’ll edit the file.

echo “My Frist Project” >> README.md

Open the file in VIM

vim file-name.text

  • At this point the file is read only, and we need to open “insert mode” to apply changes.

Edit file

Click “i” in your keyboard

Apply changes to the file, in our case fix “Frist” to “First”. Once you are done, go to the next step (i’d recommend you to edit the file through different commands to practice from the bottom cheat sheet).

Exit the insert mode

Press “ESC” button to exist back to read only mode

Save changes

Press “:” to start and write commands, then to write “w” (see below full command).

:wq

Then press enter to submit the changes.

Check that our changes apply

We’ll use the command cat just to read the file and look into it. We can also use “vim” command to get to read only mode then press “:q” (without the quotes) to exist the file without applying changes.

cat README.md

Or

vim README.md

Summary

We know a few commands, we’ve done one flow of work. In the next section we’ll see a cheatsheet of vim commands so we could work with files faster.

VIM cheatsheet

Leave a Reply

Your email address will not be published. Required fields are marked *

All rights reserved 2024 ©