Skip to content

Linux Vim Guide

Mattscreative edited this page Dec 5, 2025 · 2 revisions

Linux Vim Guide

Complete beginner-friendly guide to Vim text editor on Linux, covering Arch Linux, CachyOS, and other distributions including installation, modes, commands, and configuration.


Table of Contents

  1. Vim Installation
  2. Vim Modes
  3. Basic Commands
  4. Advanced Commands
  5. Vim Configuration
  6. Troubleshooting

Vim Installation

Install Vim

Arch/CachyOS:

# Install Vim
sudo pacman -S vim

# Or Neovim
sudo pacman -S neovim

Debian/Ubuntu:

sudo apt install vim

Fedora:

sudo dnf install vim

Launch Vim

Start Vim:

# Open file
vim filename.txt

# Or
vi filename.txt

Vim Modes

Normal Mode

Default mode:

  • Navigation: Move cursor
  • Commands: Execute commands
  • Enter: Press Esc to return

Insert Mode

Edit text:

  • Enter: Press i, a, or o
  • Type: Edit text normally
  • Exit: Press Esc

Visual Mode

Select text:

  • Enter: Press v
  • Select: Use arrow keys
  • Exit: Press Esc

⌨ Basic Commands

Navigation

Move cursor:

  • h, j, k, l: Left, down, up, right
  • w: Next word
  • b: Previous word
  • 0: Beginning of line
  • $: End of line

Editing

Edit text:

  • i: Insert before cursor
  • a: Insert after cursor
  • o: New line below
  • O: New line above
  • x: Delete character
  • dd: Delete line

Save and Exit

File operations:

  • :w: Save
  • :q: Quit
  • :wq: Save and quit
  • :q!: Quit without saving

Advanced Commands

Search and Replace

Find text:

  • /pattern: Search forward
  • ?pattern: Search backward
  • n: Next match
  • N: Previous match

Replace:

  • :%s/old/new/g: Replace all
  • :%s/old/new/gc: Replace with confirm

Copy and Paste

Yank and paste:

  • yy: Copy line
  • yw: Copy word
  • p: Paste after
  • P: Paste before

Vim Configuration

Configuration File

Edit config:

# Edit vimrc
vim ~/.vimrc

# Or Neovim
vim ~/.config/nvim/init.vim

Common Settings

Configuration:

" Enable line numbers
set number

" Enable syntax highlighting
syntax on

" Set tab size
set tabstop=4
set shiftwidth=4

" Enable mouse
set mouse=a

Troubleshooting

Vim Not Starting

Check installation:

# Check Vim
which vim
vim --version

# Install if missing
sudo pacman -S vim

Stuck in Vim

Exit Vim:

# Press Esc
# Then type:
:q!
# Press Enter

Summary

This guide covered Vim installation, modes, commands, and configuration for Arch Linux, CachyOS, and other distributions.


Next Steps


This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.

Clone this wiki locally