Using Vim

Download PDF

1. Opening a File in Vim

To open a file in Vim, use the following command:

vim filename.ext

2. Vim Modes

Vim operates in different modes:

3. Essential Vim Commands

Basic commands to get started:

4. Navigating in Vim

Use the following keys for navigation:

5. Example: Creating and Running a Script

Follow these steps to create, edit, and execute a simple script using Vim.

5.1 Step 1: Create a New File

Open the terminal and create a new file with Vim:

vim my_script.sh

5.2 Step 2: Write the Script

Once inside Vim, press i to enter Insert mode, then add the following content:

#!/bin/bash
echo "Hello, Vim!"
    

After writing the content, press Esc to exit Insert mode.

5.3 Step 3: Save and Exit

Save the file by typing:

:wq

5.4 Step 4: Grant Execution Permissions

Make the script executable by running:

chmod +x my_script.sh

5.5 Step 5: Run the Script

Execute the script using the following command:

./my_script.sh

You should see the output:

Hello, Vim!

Author: Georgina Woo