---
# System prepended metadata

title: Simple Vim Instruction
tags: [Learning Notes]

---

Simple Vim Instruction
===
###### tags: `Learning Notes`
:::info
**※ Mac and Linux already have Vim in Terminal.**
:::

## 1. Create a file
Typing the following code in your terminal, remember to change [file name] to real file name.

Additionally, if you already have a file, you can use vim [file name] to open and edit your code.

```
& vim [file name]
```
![](https://i.imgur.com/2vFgKmJ.png)


## 2. Normal Mode
After that, We will go into **Normal mode**.

![](https://i.imgur.com/AwkEpUb.png)

Here you can use the following command:
* i: insert mode #In this mode we can compile our code.
* esc: quit insert mode, back to normal mode.
* ":" + "w": save file.
* ":" + "q": close file 
**#Additionally, you can use ":qw" to save and close file at the same time.**
**#Note that w and q are lower case.**

## 3. Insert Mode
Press "i" of your keyboard, you will go into insert mode. Then you can  start to compile your code.

![](https://i.imgur.com/N0mhDge.png)

After that, press "Esc" to quit insert mode. Back to normal, type ":wq" to save and close the file.

![](https://i.imgur.com/dsI45Ia.png)

## 4. Run your code
**Before doing the following, make sure you are at the directory of your code.**
```
$ g++ -Wall [file name] -o [executable file name] #[1]
$ ./[executable file name] #[2]
```
[1]: Create a executable file, it can have same name of your original file.
[2]: Run the executable code. 

![](https://i.imgur.com/CUY61PY.png)




## Reference
The simple instruction of vim is above, if you want to learn more about vim, you can check the following:

[Linux下使用Vim進行C／C++ 編程基礎知識詳解](https://topic.alibabacloud.com/tc/a/basic-knowledge-of-cc--programming-using-vim-in-linux_1_57_31907785.html
)
[vi/vim複製貼上命令](https://www.itread01.com/p/200717.html)

{%youtube Yk4s-WLjxug %}
