Basic Vim Commands
| Vim |
In this tutorial, you will learn the essential Vim commands to navigate, edit, and save files efficiently. These commands form the foundation for working with Vim quickly and productively.
By the end, you will have the confidence to move between files, edit text, and save your changes without relying on a mouse or external menus.
1. Opening and Exiting Vim
- Open a file:
vim file_name.txt
-
Exiting Vim:
-
:q→ quit (if no changes have been made) :q!→ quit without saving changes:wqorZZ→ save and quit
2. Vim Modes
Vim has several modes. The most important are:
- Normal: default mode, used for navigation and executing commands.
- Insert: mode for inserting text (
i,I,a,A,o,O). - Visual: mode for selecting text (
v,V,Ctrl+v). - Command-line: used to execute commands starting with
:(:w,:q, etc.).
3. Basic Navigation
- Move the cursor by characters:
h(left),l(right) - Move the cursor by lines:
j(down),k(up) - Go to the beginning of the line:
0 - Go to the end of the line:
$ - Jump to a word:
w(start) /e(end)
4. Editing Text
- Insert text:
i(before the cursor),a(after the cursor) - Delete text:
x(character),dd(entire line) -
Copy and paste:
-
Copy line:
yy - Paste:
p
5. Saving Changes
- Save file:
:w - Save and quit:
:wq - Force save:
:w!
6. Useful Shortcuts
- Undo:
u - Redo:
Ctrl+r - Repeat last command:
.
With these basic commands, you can start using Vim efficiently. In the upcoming tutorials, we will dive into advanced modes, buffers, windows, and customization with
.vimrc.