Getting Started With Vim For Beginners

Suprim Regmi
6 min readApr 30, 2021

Introduction

VIM is a simple text editor. It is an improved version of Vi of Bill Joy’s. VIM is a simple yet very powerful modal text editor which comes pre-installed in Unix-like operating systems. Vim has different operating modes that’s why it is also called modal editor. Vim is the editor of choice for many developers because it is open-source and has so many configurations and plugins to play with. VIM is becoming more popular than ever among developers and power users. According to StackOverflow’s 2019 survey titled `Most Popular Development Environments` VIm is among the top 5 development tools for web developers. Vim has more than 22k stars on GitHub. Because of its popularity many Shell, IDE, browsers support Vim emulation mode.

Why Vim?

So if you are a beginner and just heard about Vim then you might be wondering Why Vim? Should I learn Vim in 2020? Here are the reasons that you should learn Vim.

  1. Vim is Everywhere

You can find it on any Unix distribution. It comes pre-installed on Linux, Mac, different servers, etc. If you are a Windows user install vim from here. Moreover, It’s totally free and open-source.

2. Incredibly Fast

One of the main strengths of Vim is its simplicity. It’s lightweight and uses less memory as opposed to other text-editors. Vim uses fewer system resources which makes it incredibly fast.

3. Tons of Plugins and Highly Configurable

Vim has so many plugins that you can choose and use according to your preferences and requirements. Some of the popular plugins are Nerd Tree, TabNine, Vim-Fugitive, etc. These plugin managers can be managed and installed from Vim’s config file called Vimrc.

4. Portable Configurations

Vim configuration and plugin can be portable to the next pc or computer. The only thing you need to do is copy the content of the .vimrc file.

5. Supports any file format and programming languages

Vim supports any file type and almost all programming languages.

6. Will saves you time in the long run

Getting used to Vim takes time. But, once you start learning and customizing keyboard bindings it will save time and efficiency in the long run

Quick Opening and Closing Vim

So now you know some background and basics of Vim. So, how to get started?

  • To open vim first open the terminal by pressing `ctrl + Alt + t`.
  • Then type `vim`, on your terminal will look like this
  • Press `i` which will change Vim to insert mode, you can see ` — INSERT — ` at the bottom left corner. Now, you can type text or anything.
  • Now, How to quit vim? To quit Vim follow these steps.
  • Press the` Esc` key: you should see the ` — INSERT — ` label vanish from the bottom left.
  • Then, press colon(:) by pressing `shift + :` on keyboard
  • Now you can pass different commands like `q` for quit, `wq` for write and quit, `w` for write.
  • Then type `:wq filetype` or `:wq newfile.txt` or whatever file extension type you like. Then press `enter` this will create and save files and exit from Vim.
  • Alternatively, if you want to exit without saving or creating a file then type `Esc + Shift + zq`

Modes in VIM

Vim has in total 6 different modes. They are normal, visual, insert, command-line, select, and ex. Among these Normal, Visual, and Insert are common modes that you use most of the time. This post only covers Normal, Insert, And Visual with common operation detail.

Normal Mode: Normal mode can be accessed by pressing `Esc` from any other mode.t’s a default mode or edit mode. In this mode, you can’t insert text. It’s helpful when you are analyzing code or navigating inside a file. You can use `k`, `l`, `j`, and `h` as up, left, top, down cursor respectively.

Insert Mode: This is the mode in which we do typing or coding or writing. By pressing `i` we can go to insert mode from normal mode. We can also goto insert mode from normal mode by pressing `a` or `o`. Pressing `a` will move the cursor 1-step left and apply insert mode whereas pressing `o` will apply insert mode in the new line.

Visual Mode: This mode can be accessed by typing `v` from normal mode. Visual mode allows us to select the text, select line, or block. This mode is useful for identifying chunks of text to be manipulated.

What is .vimrc?

The .vimrc file contains all the runtime configuration settings, plugins to initialize vim when it starts. You can install different plugins in vim to make it more visually appealing and make it look like IDE. To create .vimrc follow these steps:

  • Open terminal from your home or desktop (Ctrl + Alt + t)
  • Type `vim .vimrc` This will open and create an empty .vimrc fil
  • Then save it by typing `Esc ` and then `:qw`
  • You can see the created file by typing `ls -a` on terminal

Now you know how to create .vimrc let’s add some plugins.

Adding Plugins and Functionality

There are many popular plugin managers like vim-plug, vundle, pathogen, etc. but Vundle is the most popular one. So to install the Vundle visit. Since this is a beginner guide so Instead of installing and understanding the process we will directly add .vimrc of some author’s which includes vundle and different plugins.

Here are some of the source from where you can copy configuration files:

Steps to ADD:

  • Copy all raw contents of .vimrc file from any one of the above sources
  • Open terminal(Ctrl + Alt + t)
  • Type `vim .vimrc` which will open your .vimrc.
  • Press `i` to go to insert mode then type `Shift + Ins` from your keyboard to paste copied configuration data
  • Press `Esc` to change to Normal mode then type `:wq` to write a file
  • Now, again on typing `vim` the installing process will start automatically

TidBit

  • If you messed up vimrc then just remove and start the process again
  • To remove .vimrc got to home type `rm .vimrc`
  • Again create by `vim .vimrc`

Summary

  • Vim is everywhere and isn’t going anywhere
  • Mastering Vim will increase your productivity
  • Vim is incredibly fast and its configurations are portable
  • `.vimrc` is the file that you can edit to add configurations

Final Tips

The power of Vim can be utilized by learning different commands and applying keyboard binding according to your convenience. Here are some common but important commands that you are likely to encounter on daily basis:

Common Normal/Insert Mode commands

  • :w — Write the file
  • :wq — Save and quit
  • :q! — Just quit without saving
  • i — Start insert mode at the cursor
  • :vsp Vertical split
  • ctrl+ww — Switch between Windows
  • ctrl+wq — Quit window

Common Visual Mode Commands:

  • yy — Copy as line
  • p — Paste
  • dd — Delete a line
  • x — cut current character

Here are ome useful links to help you

with vim hotkeys:

  • https://vimsheet.com/
  • https://vim.rtorr.com/
  • https://devhints.io/vim

For more content like these stay tuned,

at https://brogrammersnepal.com/ or follow me.

Any feedback or suggestions are highly appreciated.

Thank You.

--

--