0
0
Linux-cliHow-ToBeginner · 3 min read

Basic Vim Commands in Linux: Essential Guide for Beginners

In Linux, basic vim commands include i to enter insert mode for typing, :w to save changes, :q to quit, and :wq to save and quit. Use Esc to switch from insert mode back to command mode where you can navigate and run commands.
📐

Syntax

Vim operates mainly in two modes: insert mode for typing text and command mode for commands and navigation.

Basic syntax to start Vim editing a file:

  • vim filename - opens or creates a file named filename.
  • Inside Vim, press i to enter insert mode and start typing.
  • Press Esc to return to command mode.
  • Use :w to save (write) changes.
  • Use :q to quit Vim.
  • Use :wq to save and quit.
bash
vim filename

# Inside vim:
# i       # enter insert mode
# <type your text>
# Esc     # return to command mode
# :w      # save changes
# :q      # quit
# :wq     # save and quit
💻

Example

This example shows how to open a file, add text, save, and exit Vim.

bash
vim example.txt

# Press i to enter insert mode
# Type: Hello, Vim!
# Press Esc to go back to command mode
# Type :w to save
# Type :q to quit
Output
Hello, Vim!
⚠️

Common Pitfalls

Beginners often get stuck because Vim starts in command mode, so typing doesn't work until you press i to enter insert mode.

Another common mistake is trying to quit with :q without saving, which Vim blocks if there are unsaved changes.

Always press Esc before typing commands like :w or :q.

bash
Wrong way:
# Type text immediately after opening vim (no effect)
# Try :q without saving (error)

Right way:
# Press i to enter insert mode
# Type text
# Press Esc
# Type :w to save
# Type :q to quit
📊

Quick Reference

CommandDescription
vim filenameOpen or create a file
iEnter insert mode to type text
EscReturn to command mode
:wSave (write) changes
:qQuit Vim
:wqSave and quit
:q!Quit without saving changes
h, j, k, lMove cursor left, down, up, right

Key Takeaways

Press i to enter insert mode before typing text in Vim.
Use Esc to switch back to command mode to run commands.
Save changes with :w and quit with :q or :wq to save and quit.
If you want to quit without saving, use :q!.
Use h, j, k, l keys to navigate the text in command mode.