Curso de VIM #2 - Modo de inserção e modo de comandos, teclas de movimentação básica
Table of Contents
Introduction
This tutorial will guide you through the basic functionalities of the Vim text editor, focusing on the difference between command mode and insert mode, as well as basic navigation using the keyboard. Understanding these concepts is essential for efficient text editing in Vim.
Step 1: Opening and Exiting Files in Vim
To work with files in Vim, follow these steps:
-
Open a file:
- In your terminal, type the following command:
vim filename.txt
- Replace
filename.txt
with the name of the file you want to open.
- In your terminal, type the following command:
-
Exit Vim:
- If you are in command mode, type:
:q
- If you have unsaved changes and want to exit, type:
:q!
- To save changes and exit, use:
:wq
- If you are in command mode, type:
Step 2: Creating a New File in Vim
To create a new file:
- Open Vim with a new filename:
vim newfile.txt
- You can then start editing the new file directly.
Step 3: Understanding Vim Modes
Vim operates in two primary modes:
-
Command Mode:
- This is the default mode when you open Vim. You can execute commands, navigate, and manipulate text.
-
Insert Mode:
- You can enter insert mode by pressing
i
while in command mode. This allows you to input text.
- You can enter insert mode by pressing
Step 4: Entering Insert Mode
To switch to insert mode:
- Press
i
while in command mode. - You can now type and edit text freely.
Step 5: Exiting Insert Mode
To return to command mode from insert mode:
- Press the
Esc
key. This will take you back to command mode.
Step 6: Basic Navigation in Vim
You can navigate your text using the following keys:
h
: Move leftj
: Move downk
: Move upl
: Move right
These keys allow for efficient movement without leaving the home row of the keyboard.
Step 7: Saving Changes in Vim
To save any changes you've made to a file:
- Ensure you are in command mode by pressing
Esc
. - Type:
:w
Conclusion
In this tutorial, you learned how to open and create files in Vim, understand its modes, and navigate using basic keyboard shortcuts. Practicing these steps will enhance your proficiency in Vim. As a next step, explore more advanced Vim commands and customizations to further improve your text editing skills. For further learning, check out resources like vimtutor
or consider playing Vim Adventures to enhance your skills in a fun way.