VIM - Beginners Guide
Tags: vim, programming, linux, beginners
Published: 2021-10-03 10:58:54

##Introduction
VIM is a text editor for writing code, where you navigate around the screen with the **Keyboard** instead of a **Mouse**.
It is based on original UNIX text editor named **VI** which came about in 1976 by *Bill Joy*. It was later improved by *Bram Mooleenar* in 1991 with bunch of improvements and named **VIM**.

##Why VIM?
Why would you use VIM when we have modern IDEs? The answer is, when you write code, your fingers should be bound to keyboard all the time. Every time you touch mouse your work rate is interrupted.
Learning to code with VIM is same as learning something new from scratch, it will be painful at first but that pain will lead you to more precise and productive code editing in the future.

##Installation
**Linux**/**MacOS**: VIM comes preinstalled.
**Windows**: [Download VIM](https://www.vim.org/download.php), Download the installer and install it. 

##How to use
**Linux**/**MacOS**: Type "vim filename.txt" in terminal (without quotations)
**Windows**: Open "gVim8.1" from desktop or search in start menu.

##Vim Modes
VIM has many modes, but these four are commonly used:

###Normal mode

*If you see cursor thicker or little wide, means you're in normal mode.*

Normal mode is Vim's default mode and you'll be using it most of the time. When you are in normal mode you can navigate and perform operations throughout the file.

You can move cursor between characters, words, lines, sentences, paragraphs. code blocks and more.

####Characters
**"h"** (move left to character)
**"l"** (move right to character)

####Words
**"w"** (move to next word)
**"e"** (move the end of current word)
**"b"** (move back to the previous word)

####Lines
**"j"** (previous line)
**"k"** (next line)

####Sentences
**"("** (previous sentence)
**")"** (next sentence)

####Paragraphs
**"{"** (previous Paragraph)
**"}"** (next Paragraph)

For simplification:
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o2g9sh1mf3rotebof7yo.png)
 
**k** (up)
**j** (down)
**h** (left)
**l** (right)
You can also use arrow keys to navigate but for best practice you must use (k,j,h,l).


###Insert mode

Press **i** key in the normal mode to get into **insert** mode. *The word INSERT will appear at the bottom of the screen.*
You can think of it like *edit* mode, because now you can write/delete inside the file.

####Keys to get into *insert* mode:
*Make sure you're in normal mode then press,*

**i** (insert from the right of the character)
**a** (insert from the left of the character)
**I** (insert from the start of the line)
**A** (insert from the end of the line)

Once you are done with editing your file, press **Esc** key to go back to the normal mode.

###Command mode
*Commands can only be typed in **Normal** mode.*
When you're in normal mode, you can write commands. Every command starts with **":"**.

####Basic commands:
**:w** (save file)
**:q** (quit file. *but the file must be saved first*)
**:wq** (save and quit)
**:q!** (quit without saving)

*There are many more commands, but these are the common and you'll need these all the time.*

###Visual mode

When editing text with Vim, visual mode can be extremely useful for identifying chunks of text to be manipulated.

Press the **v** key to enter **visual** mode. *The word VISUAL will appear at the bottom of the screen.*

Use the Arrow keys to highlight the desired text. You can use other navigation commands, such as **w** to highlight to the beginning of the next word or **$** to include the rest of the line.
Once the text is highlighted, press the **d** key to delete/cut the text.
If you deleted too much or not enough, press **u** to undo and start again.
Move your cursor to the new location and press **p** to paste the text.

###Tips and tricks
1. To go forward 3 words, instead of **www**, we can do **3w**.
2. To go down 10 lines, instead of **jjjjjjjjjj**, we can do *10j*.
3. **dw** to delete a word.
4. **dd** to delete the entire line.
5. **x** to delete a character.
6. **r** followed by new character to replace a character.
7. To switch back to normal mode from any mode, press **Esc**.

There's still a lot to learn. Keep exploring. Happy coding.

If you learnt something from this article, please like, comment and share.

Follow me on [Instagram](https://www.instagram.com/vishwas_luhana).
Follow me on [Facebook](https://www.facebook.com/luhanavishwas).
Follow me on [Twitter](https://twitter.com/vixvos).