To open a file in Vim, use the following command:
vim filename.ext
Vim operates in different modes:
Basic commands to get started:
i
– Switch to insert mode.Esc
– Return to normal mode.:w
– Save the file.:q
– Quit Vim.:wq
– Save and quit.:q!
– Quit without saving.Use the following keys for navigation:
h
– Move leftj
– Move downk
– Move upl
– Move rightFollow these steps to create, edit, and execute a simple script using Vim.
Open the terminal and create a new file with Vim:
vim my_script.sh
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.
Save the file by typing:
:wq
Make the script executable by running:
chmod +x my_script.sh
Execute the script using the following command:
./my_script.sh
You should see the output:
Hello, Vim!
Author: Georgina Woo