> For the complete documentation index, see [llms.txt](https://docs.projectreclass.org/infrastructure/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.projectreclass.org/infrastructure/linux-basics/getting-started-with-vim.md).

# Getting started with vim

Vim is an in terminal text editor. The improved version of vi. One of these variants is often preinstalled on every linux host.

## How to use vim

Vim allows you edit files, it'll also create any files that don't exist and open them for editing. Typing `vim [filename]` is the same as typing `touch [filename]` followed by `vim [filename]` you still open an empty file for editing. Let's start by creating and editing a file.&#x20;

```
vim hello.sh
```

{% hint style="info" %}
We'll be writing a simple script using vim. Vim has two basic modes - a command mode and an Insert mode. Insert mode allows us to write code and make changes to a file. While command mode allows us to change things about our vim session, issue Unix and Linux commands as well as save and or quit the vim session.&#x20;

There's also a visual mode but we won't be using that here.&#x20;
{% endhint %}

Now that we're in our file we need to enter `insert mode` this is simple within vim but not intuitive. Simply press `i` . This will change us from `command mode` to `insert mode` we'll type two things: our shebang line to inform our OS how to execute our script `#!/bin/bash` and our code underneath it `echo "Hello World"`

{% code title="hello.sh" %}

```bash
#!/bin/bash # This is a shebang it tells our OS how to execute our script
echo "Hello World" # echo outputs data to stdout aka prints to the shell
```

{% endcode %}

So now that we've written our first script. How do we save it? You'll first need to enter `command mode` to do this press the `[escape]` key on your keyboard. If you do not have one for some reason you can hold the `[control] + [` key at the same time.&#x20;

Once you've entered command mode you won't be able to edit text in the same way. There are several keybindings so don't start pressing random keys.&#x20;

Once you've entered `command mode` you'll need to type the colon key `:` this should show up at the bottom of the editor.&#x20;

![Ensure the colon is present](https://3774373334-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MbNAC5C7H01i7puPRcA%2F-MbPI1YzrnL31mXNu8JQ%2F-MbPNb14TluDZXC9TJjH%2FScreen%20Shot%202021-06-04%20at%2011.15.30%20PM.png?alt=media\&token=08f384a1-c8b1-4b87-9003-3109bfe081c6)

{% hint style="info" %}
If you do not see the colon continue attempting to enter the command mode and enter the colon until it appears
{% endhint %}

Once the colon is present you can type `wq` to save your changes and exit vim.&#x20;
