A Beginner’s Guide to Vim

An introduction to the command line text editor, and a few helpful tips to get you started.

You do not need to be a command-line wizard to be able to use Vim. Using Vim consists of three simple steps: opening Vim, making the necessary text edits, then saving and exiting.

Opening Vim

vim Helloworld.txt

Using the vim command followed by a file name will result in opening that file in the vim editor. If that file does not already exist in your current directory, it will be created.

Result of opening a new file using vim
Result of opening a new file using vim
Result of opening a new file using vim

In this case, we see [New], because I did not have a Helloworld.txt already present in my directory, so I am creating it. And don’t worry about the date and time you might be thinking is the pics from 1970. No, it is not. It is just the Unix time Epoch. It shows whenever you create a new file. Once you save this file it will show your normal date and time.

Using Vim

In order to go any further, we need to get a grasp on how Vim generally works. These are the key concepts you need to remember:

  • Vim is a text editor (just like VSCode, Sublime, etc) that runs in your terminal.
  • Once you open Vim, you get into an interactive mode.
  • Vim has multiple modes.
  • Vim operates on commands.
  • Vim is extremely configurable.

The theory behind modes & commands:

When you first open Vim, you are in NORMAL mode (otherwise knows as a MASTER mode). This is like your home base. You always want to make sure you are in NORMAL mode before you execute any commands. Press i to jump to INSERT mode. Note that once you are in INSERT mode, all your keystrokes will result in text. In other words, you will not be able to enter any commands. In order to do so, you will need to go back to NORMAL mode, which is easily achievable by pressing the <ESC> key.

Feel free to reference the diagram below. Keep in mind that VISUAL mode is simply another mode, just like INSERT mode, accessible by pressing v.

Source: https://github.com/nilp0inter/Vim-for-Muggles

Once you press the <ESC> key you enter in VISUAL mode and Every Vim command starts with a colon : and is followed by a special keyword. Remember that you can only execute commands in NORMAL mode.

Now that we have a basic understanding of some commands let’s get your hands dirty with some hands-on. We will add some text to your file while in INSERT mode.

Vim’s Insert mode

Closing Vim

To wrap this up, let’s make sure to have StackOverflow's most popular question answered. Numerous people (including me) end up opening Vim by mistake, and not knowing how to exit it (in my case, I was learning about cronjob and I select the editor as Vim ).

To exit the vim make sure you are in Normal mode by pressing <ESC> and use the adequate :q command from the list below to quit Vim.

:q - no changes were made
:q! - trash all changes
:wq - save the changes
Using the :wq command to write changes and quit Vim.

Ok so if you follow Tomnomnom . He has some hack to exit vim do check it out.

Bonus Tips

Cut, Copy and paste in Normal mode.

Vim has its own terminology for copying, cutting, and pasting. Copy is called yank (y), cut is called delete (d), and paste is called put (p).

  • yy - Yank (copy) the current line, including the newline character.
  • dd - Delete (cut) the current line, including the newline character
  • To put the yanked or deleted text, move the cursor to the desired location and press p to put (paste) the text after the cursor or P to put (paste) before the cursor

Although this article might help you get your feet wet with Vim by accomplishing basic text editing operations quickly via the terminal, it only encompasses about 1% of Vim’s potential. If you want to learn more, vimtutor is a fantastic built-in command that will pull up important Vim lessons on your terminal. You can also access it on the web via vimtutor.

🎨 Personalize Vim by editing .vimrc: https://dougblack.io/words/a-good-vimrc.html

I will cover about .vimrc file in another blog until then stay curious.✌️

Have any queries hit me a dm on

Twitter: https://twitter.com/0x_Mantis

LinkedIn: https://www.linkedin.com/in/sach1nmaurya/

Wannabe a ethical hacker

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store