Linux Vim Guide - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
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
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
Escto return
Insert Mode
Edit text:
- Enter: Press
i,a, oro - 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
- Text Editors - Text editors
- nano Guide - nano editor
- Vim Documentation:
man vim
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.