Skip to main content
graphwiz.aigraphwiz.ai
← Back to Cheatsheets

Vim, Nano & Emacs Cheatsheet

DevOps
vimnanoemacstext-editorsterminalsysadmin

Vim, Nano & Emacs Cheatsheet

A practical quick-reference guide for the three most common terminal text editors. Whether you need Vim's power for rapid code editing, Nano's simplicity for quick config changes, or Emacs's extensibility for a full development environment — this sheet has you covered.


Vim

Vim (Vi IMproved) is a modal text editor. Every action is a keystroke — no menus, no mouse. Master the modes and you edit at the speed of thought.

Modes

# Start Vim
vim file.txt          # open or create file
vim                   # empty buffer
vim -R file.txt       # read-only mode
view file.txt         # alias for vim -R
```text

| Mode | Enter | Exit / Switch | Purpose |
| ---- | ----- | ------------- | ------- |
| **Normal** | `Esc` (always returns here) | — | Navigation, commands, operators |
| **Insert** | `i`, `a`, `o`, `I`, `A`, `O` | `Esc` | Text input |
| **Visual** | `v`, `V`, `Ctrl+v` | `Esc` | Text selection |
| **Command-line** | `:` | `Enter` or `Esc` | Ex commands (save, quit, search) |
| **Replace** | `R` | `Esc` | Overtype characters |
| **Select** | `gh` (after `g`) | `Esc` | Like Visual but typing replaces selection |

### Navigation

#### Character & Line

```bash
h j k l       # left, down, up, right
0             # beginning of line
^             # first non-blank character
$             # end of line
gg            # first line of file
G             # last line of file
5gg or 5G     # go to line 5
```text

#### Words, Sentences & Paragraphs

```bash
w             # next word start
b             # previous word start
e             # next word end
ge            # previous word end
W             # next WORD (whitespace-delimited)
B             # previous WORD
E             # end of WORD
)             # next sentence
(             # previous sentence
}             # next paragraph (blank-line separated)
{             # previous paragraph
%             # matching bracket/paren/brace
```text

#### Scrolling

```bash
Ctrl+f        # page down
Ctrl+b        # page up
Ctrl+d        # half page down
Ctrl+u        # half page up
Ctrl+e        # scroll down one line
Ctrl+y        # scroll up one line
H             # top of screen
M             # middle of screen
L             # bottom of screen
zt            # scroll current line to top
zz            # scroll current line to center
zb            # scroll current line to bottom
```text

#### Searching

```bash
/pattern      # search forward
?pattern      # search backward
n             # repeat search forward
N             # repeat search backward
*             # search forward for word under cursor
#             # search backward for word under cursor
:noh          # clear search highlight
```text

### Editing

#### Insert Mode Entry Points

```bash
i             # insert before cursor
a             # insert after cursor
I             # insert at beginning of line (before first non-blank)
A             # insert at end of line
o             # open line below
O             # open line above
s             # delete character and enter insert
S             # delete entire line and enter insert
```text

#### Delete, Change, Yank

```bash
x             # delete character under cursor
X             # delete character before cursor
dd            # delete entire line
dw            # delete to next word start
d$ or D       # delete to end of line
d0            # delete to beginning of line
dgg           # delete to start of file
dG            # delete to end of file
cc or S       # change (delete + insert) entire line
cw            # change to next word start
c$ or C       # change to end of line
yy or Y       # yank (copy) entire line
yw            # yank word
y$            # yank to end of line
ygg           # yank to start of file
yG            # yank to end of file
p             # paste after cursor
P             # paste before cursor
```text

#### Repeat & Undo

```bash
.             # repeat last edit command
u             # undo
Ctrl+r        # redo
```text

#### Indentation

```bash
>>            # indent current line
<<            # unindent current line
5>>           # indent 5 lines
==            # auto-indent current line
gg=G          # auto-indent entire file
```text

### Search & Replace

```bash
# Basic substitute
:s/old/new/            # replace first occurrence on current line
:s/old/new/g           # replace all on current line
:s/old/new/gc          # replace all with confirmation

# Range substitute
:%s/old/new/g          # replace all in entire file
:5,20s/old/new/g       # replace in lines 5–20
:'<,'>s/old/new/g      # replace in visual selection

# Advanced patterns
:%s/\t/  /g            # replace tabs with 2 spaces
:%s/^\s\+//            # remove leading whitespace
:%s/\s\+$//            # remove trailing whitespace
:%s/foo\|bar/baz/g     # replace foo or bar with baz
```text

### Marks

```bash
m{a-z}        # set local mark (a-z)
m{A-Z}        # set global mark (file-wide, uppercase)
'{a-z}        # jump to local mark (line start)
'{A-Z}        # jump to global mark
''            # jump back to last jump position
`{a-z}        # jump to exact mark position (column)
:marks        # list all marks
:delmarks a b # delete marks a and b
```text

### Registers

```bash
"a            # use register 'a' for next delete/yank
"ayy          # yank line into register a
"ap           # paste from register a
"0p           # paste from last yank register
"+p           # paste from system clipboard
"+y           # yank into system clipboard
"*p           # paste from primary selection (X11)
:registers    # show all registers
```text

### Macros

```bash
q{a-z}        # start recording macro into register a
q             # stop recording
@a            # replay macro a
@@            # replay last used macro
5@a           # replay macro a five times
:reg a        # view contents of macro register a
```text

#### Practical Macro Example

```bash
# Record a macro to wrap a word in quotes
qa             # start recording into register a
i"<Esc>        # insert opening quote, return to normal
ea             # move to end of word
a"<Esc>        # insert closing quote
q              # stop recording

# Apply to every word on a line
# Position cursor on first word, then:
qa i"<Esc> ea a"<Esc> q    # (this is the macro above)
100@a                       # replay 100 times (stops at end of line)
```text

### Visual Mode

```bash
v             # character-wise visual mode
V             # line-wise visual mode
Ctrl+v        # block visual mode
o             # go to other end of selection
gv            # re-select last visual selection
```text

#### Visual Mode Operations

```bash
# After selecting text in visual mode:
d             # delete selection
c             # change selection
y             # yank (copy) selection
>             # indent selection
<             # unindent selection
~             # toggle case of selection
u             # lowercase selection
U             # uppercase selection
:sort         # sort selected lines
:!fmt         # reformat paragraph via fmt
```text

#### Visual Block Mode

```bash
Ctrl+v        # enter block visual mode
I             # insert at left edge of block (applies to all lines)
A             # append at right edge of block
$             # extend block to end of each line
```text

##### Practical Block Mode Example

```bash
# Comment out multiple lines with //
1. Move to first line
2. Ctrl+v to enter block mode
3. jj to select 3 lines down
4. I to insert at the block's left edge
5. Type // then Esc
6. The // is inserted on all selected lines
```text

### Buffers, Windows & Tabs

#### Buffers

```bash
:ls or :buffers     # list all buffers
:bnext or :bn       # next buffer
:bprev or :bp       # previous buffer
:bfirst             # first buffer
:blast              # last buffer
:b 3                # go to buffer 3
:b file.txt         # go to buffer by name (partial match)
:bd                 # close current buffer
:bd 3               # close buffer 3
:bw                 # wipe buffer (close + delete)
:e file2.txt        # open file in new buffer
:split file2.txt    # open file in horizontal split
:vsp file2.txt      # open file in vertical split
```text

#### Windows (Splits)

```bash
:split or :sp       # horizontal split
:vsplit or :vsp     # vertical split
Ctrl+w s            # horizontal split
Ctrl+w v            # vertical split
Ctrl+w h            # move to left window
Ctrl+w j            # move to below window
Ctrl+w k            # move to above window
Ctrl+w l            # move to right window
Ctrl+w w            # cycle through windows
Ctrl+w W            # cycle backwards
Ctrl+w =            # equalize window sizes
Ctrl+w _            # maximize current window
Ctrl+w |            # maximize current window (vertical)
Ctrl+w q            # close current window
Ctrl+w o            # close all other windows
```text

#### Tabs

```bash
:tabnew             # new tab
:tabedit file.txt   # open file in new tab
:tabclose or :tc    # close current tab
:tabnext or :tn     # next tab
:tabprev or :tp     # previous tab
:tabfirst or :tf    # first tab
:tablast or :tl     # last tab
:tabs               # list all tabs
gt                  # next tab
gT                  # previous tab
5gt                 # go to tab 5
```text

### File Operations

```bash
:w                   # save
:w!                  # force save (override permissions)
:w file.txt          # save as new file
:q                   # quit
:q!                  # quit without saving
:wq or ZZ            # save and quit
:x                   # save and quit (only if modified)
:e!                  # reload file from disk
:e file.txt          # open another file
:r file.txt          # insert contents of file below cursor
:r !command          # insert command output below cursor
:saveas file.txt     # save under new name
```text

### .vimrc Basics

```bash
# ~/.vimrc — essential settings

" General
set nocompatible              # required for Vim features
set encoding=utf-8
set fileencoding=utf-8
set number                    # show line numbers
set relativenumber            # relative line numbers for easy jumps
set scrolloff=8               # keep 8 lines of context when scrolling
set sidescrolloff=8
set signcolumn=yes            # always show sign column
set cursorline                # highlight current line
set colorcolumn=80            # highlight column 80
set wrap                      # wrap long lines
set linebreak                 # break at word boundaries
set showbreak=↪               # show wrap indicator
set breakindent               # indent wrapped lines

" Indentation
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab                 # use spaces instead of tabs
set smartindent
set autoindent
filetype indent on            # load indent rules per filetype

" Search
set hlsearch                  # highlight search results
set incsearch                 # incremental search
set ignorecase
set smartcase                 # case-sensitive when uppercase present

" Performance
set lazyredraw                " don't redraw during macros
set updatetime=300            " faster update time

" Persistent undo
set undofile
set undodir=~/.vim/undodir

" Key mappings
let mapleader=" "
nnoremap <leader>w :w<CR>
nnoremap <leader>q :q<CR>
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
```text

---

## Nano

GNU Nano is a simple, modeless terminal editor. Every keystroke is either text or a command — no modes to remember. Ideal for quick edits and SSH sessions.

### Basic Keybindings

```bash
# Start Nano
nano file.txt         # open or create file
nano +10 file.txt     # open at line 10
nano -l file.txt      # show line numbers
nano -B file.txt      # create backup on save (.save)
nano -m file.txt      # enable mouse support
```text

| Key | Action | Description |
| --- | ------ | ----------- |
| `Ctrl+G` | Help | Show built-in help (lists all shortcuts) |
| `Ctrl+O` | Save | Write file to disk (prompts for filename) |
| `Ctrl+X` | Exit | Close Nano (prompts to save if modified) |
| `Ctrl+K` | Cut | Cut current line (or selected text) |
| `Ctrl+U` | Paste | Paste last cut text |
| `Ctrl+T` | Spell | Run spell checker (if configured) |
| `Ctrl+J` | Justify | Reformat/justify current paragraph |

### Navigation

| Key | Action |
| --- | ------ |
| `Ctrl+A` | Beginning of line |
| `Ctrl+E` | End of line |
| `Ctrl+Y` | Page up |
| `Ctrl+V` | Page down |
| `Ctrl+F` | Move forward one character |
| `Ctrl+B` | Move back one character |
| `Ctrl+Space` | Next word |
| `Alt+Space` | Previous word |
| `Ctrl+_` | Go to specific line (enter line number) |
| `Alt+G` | Go to specific line (alternative) |
| `Ctrl+C` | Show current cursor position (line, column) |
| `Alt+]` | Go to matching bracket |
| `Alt+( or Alt+)` | Go to previous/next paragraph |

### Search & Replace

```bash
# Search
Ctrl+W             # search forward
Alt+W              # search backward
Alt+Q              # search without regex

# Replace
Ctrl+\             # search and replace (prompted)
# Enter search text, press Enter
# Enter replacement text
# Y = replace this, N = skip, A = replace all, Ctrl+C = cancel
```text

### Cut, Copy & Paste

| Key | Action |
| --- | ------ |
| `Alt+A` | Start/select text marking |
| `Ctrl+6` | Toggle mark (alternative) |
| `Ctrl+K` | Cut marked text or current line |
| `Alt+6` | Copy marked text (doesn't cut) |
| `Ctrl+U` | Paste (uncut) last cut/copied text |

### File Operations

| Key | Action |
| --- | ------ |
| `Ctrl+R` | Insert file (read a file into current buffer) |
| `Ctrl+O` | Write out (save) — `Alt+D` to save with different name |
| `Ctrl+X` | Exit |

### .nanorc Configuration

```bash
# ~/.nanorc — Nano configuration

# Line display
set linenumbers
set constantshow            # always show cursor position

# Editing behavior
set tabsize 4
set tabstospaces
set autoindent
set cutoff                  # hard-wrap at 80 chars (or set fill 80)
set multibuffer             # insert-to-end, not replacing buffer

# Backup & history
set backup
set historylog
set mouse

# Syntax highlighting
include /usr/share/nano/*.nanorc
# Or include specific files:
include /usr/share/nano/sh.nanorc
include /usr/share/nano/python.nanorc
include /usr/share/nano/javascript.nanorc
include /usr/share/nano/html.nanorc
include /usr/share/nano/yaml.nanorc
include /usr/share/nano/dockerfile.nanorc
include /usr/share/nano/systemd.nanorc
```text

### Custom Syntax Highlighting

```bash
# Add to ~/.nanorc

# Custom syntax for .env files
syntax "env" "\.env$"
color brightwhite "^.*="
color cyan "^[A-Z_]+="
color yellow "\"[^\"]*\""
color green "\'[^\']*\'"

# Custom syntax for log files
syntax "logs" "\.log$"
color brightred "ERROR"
color brightyellow "WARN(ING)?"
color brightgreen "INFO"
color brightmagenta "DEBUG"
color blue "^[0-9]{4}-[0-9]{2}-[0-9]{2}"
```text

### Common Flags

```bash
nano                  # basic editor
nano -B file.txt      # create backup file on save
nano -E file.txt      # tab-to-space conversion
nano -l file.txt      # show line numbers
nano -m file.txt      # enable mouse
nano -S file.txt      # smooth scrolling
nano -c file.txt      # show cursor position constantly
nano -i file.txt      # auto-indent new lines
nano -u file.txt      # undo support (default in modern Nano)
nano -r 120 file.txt  # set fill column to 120
nano -v file.txt      # view mode (readonly)
nano -w file.txt      # don't wrap long lines
nano -R file.txt      # enable regular expression search
```text

### Practical Nano Workflow

```bash
# Quick SSH config edit
ssh server
sudo nano /etc/ssh/sshd_config
# Edit, Ctrl+O to save, Ctrl+X to exit
sudo systemctl restart sshd

# Edit a Docker Compose file with syntax highlighting
nano docker-compose.yml

# Create a new script with line numbers
nano -l -i deploy.sh

# View a log file (readonly mode)
nano -vw /var/log/syslog
# Search with Ctrl+W, page with Ctrl+Y/Ctrl+V
```text

---

## Emacs

GNU Emacs is a Lisp-based, infinitely extensible editor. It's not just a text editor — it's a complete computing environment. Key convention: `C-` = Ctrl, `M-` = Alt (Meta).

### Basic Navigation

| Key | Action | Mnemonic |
| --- | ------ | -------- |
| `C-f` | Forward one character | Forward |
| `C-b` | Back one character | Back |
| `C-n` | Next line | Next |
| `C-p` | Previous line | Previous |
| `C-a` | Beginning of line | Beginning of alphabet |
| `C-e` | End of line | End |
| `M-f` | Forward one word | Meta Forward |
| `M-b` | Back one word | Meta Back |
| `M-a` | Beginning of sentence | Meta Beginning |
| `M-e` | End of sentence | Meta End |
| `C-v` | Page down | View |
| `M-v` | Page up | Meta View |
| `C-l` | Re-center cursor on screen | Line |
| `M-<` | Beginning of buffer | Meta Less-than |
| `M->` | End of buffer | Meta Greater-than |
| `C-g` | Cancel/quit current command | Go away |

### File & Buffer Management

```bash
# Files
C-x C-f       # find (open) file
C-x C-s       # save file
C-x C-w       # write as (save as)
C-x C-c       # exit Emacs
C-x k         # kill (close) current buffer
C-x C-j       # open Dired (file manager)

# Buffers
C-x b         # switch buffer (with auto-complete)
C-x C-b       # list all buffers
C-x <left>    # previous buffer
C-x <right>   # next buffer
C-x k         # kill buffer
```text

### Editing

| Key | Action |
| --- | ------ |
| `Backspace` | Delete previous character |
| `C-d` | Delete next character |
| `M-Backspace` | Delete previous word |
| `M-d` | Delete next word |
| `C-k` | Kill to end of line (cut) |
| `M-k` | Kill to end of sentence |
| `C-w` | Kill region (cut selection) |
| `M-w` | Copy region |
| `C-y` | Yank (paste) |
| `M-y` | Cycle through kill ring after yank |
| `C-/` or `C-x u` | Undo |
| `C-Shift-/` or `C-x C-Shift-u` | Redo (Emacs 28+) |
| `C-Space` | Set mark (begin selection) |
| `C-x h` | Select entire buffer |
| `C-t` | Transpose two characters |
| `M-t` | Transpose two words |
| `C-x C-t` | Transpose two lines |
| `M-c` | Capitalize word |
| `M-u` | Uppercase word |
| `M-l` | Lowercase word |
| `M-q` | Fill (reflow) paragraph |

### Search & Replace

```bash
# Incremental search
C-s           # search forward (incremental)
C-r           # search backward (incremental)
# While searching:
#   C-s again = jump to next match
#   C-r again = jump to previous match
#   C-g = cancel search

# Non-incremental search
M-C-s         # search forward with regex
M-C-r         # search backward with regex

# Replace
M-%           # query-replace (prompted replace)
#   y = replace, n = skip, ! = replace all, q = quit

# Replace with regex
C-M-%         # query-replace-regexp
```text

### Kill & Yank Ring

```bash
# The kill ring is Emacs's multi-item clipboard
C-k           # kill (cut) line from cursor to end
C-k C-k       # kill entire line (including newline)
C-w           # kill region (cut selection)
M-w           # copy region (without killing)
C-y           # yank (paste most recent kill)
M-y           # cycle kill ring — press repeatedly after C-y

# Example: paste something from 3 cuts ago
C-y M-y M-y M-y
```text

### Window Management

```bash
# Split windows
C-x 2         # split horizontally
C-x 3         # split vertically
C-x 1         # close all other windows
C-x 0         # close current window

# Navigate between windows
C-x o         # switch to next window

# Resize windows
C-x ^         # grow window height
C-x }         # grow window width
C-x {         # shrink window width
C-x +         # balance all windows
```text

### Org-Mode Basics

Org-Mode is Emacs's killer app — an outline-based document and task management system built in.

```bash
# Open an Org file
C-x C-f todo.org

# Outline navigation
Tab           # cycle visibility (fold/unfold subtree)
S-Tab         # cycle global visibility
C-c C-n       # next heading
C-c C-p       # previous heading
C-c C-f       # forward heading (same level)
C-c C-b       # backward heading (same level)
C-c C-u       # go to parent heading

# Structure editing
M-Enter       # new heading/item below
M-S-Enter     # new heading (same level as parent)
M-Left/Right  # promote/demote subtree
M-S-Left/Right # promote/demote subtree with children
M-Up/Down     # move subtree up/down

# Todo lists
C-c C-t       # cycle todo state (TODO → DONE → TODO)
S-Right/Left  # cycle through todo keywords

# Tables (built-in spreadsheet)
C-c |         # create or convert to table
Tab           # move to next cell / re-align
S-Tab         # move to previous cell
M-Left/Right  # move column
M-Up/Down     # move row
C-c -         # insert horizontal line
C-c Enter     # insert row below
C-c C-c       # recalculate table formulas

# Links
C-c C-l       # insert/edit link
C-c C-o       # open link at point

# Export
C-c C-e       # export dispatcher
#   h h = export to HTML
#   l p = export to PDF (via LaTeX)
#   l o = export to ODT
#   m m = export to Markdown
```text

#### Practical Org-Mode Example

```bash
# Create a task list
* Project Alpha
** TODO Research competitor features
   SCHEDULED: <2026-04-25>
** TODO Design API schema
   SCHEDULED: <2026-04-28>
** DONE Write initial documentation
   CLOSED: [2026-04-18 Sat]

# A simple table with formula
| Item     | Qty | Price | Total |
|----------+-----+-------+-------|
| Widget   |   3 |    10 |    30 |
| Gadget   |   2 |    25 |    50 |
| Doohickey|   1 |    15 |    15 |
|----------+-----+-------+-------|
| Total    |   6 |       |    95 |
#+TBLFM: @5$4=vsum(@2$4..@4$4)
```text

### .emacs / emacs.d Init

```bash
# ~/.emacs.d/init.el — modern Emacs configuration

;; Package management
(require 'package)
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
                         ("gnu"   . "https://elpa.gnu.org/packages/")))
(package-initialize)
(unless package-archive-contents
  (package-refresh-contents))

;; Use-package for clean config (built-in since Emacs 29)
(setq use-package-always-ensure t)

;; UI
(tool-bar-mode -1)          ; hide toolbar
(menu-bar-mode -1)          ; hide menubar
(scroll-bar-mode -1)        ; hide scrollbar
(column-number-mode 1)      ; show column number
(global-display-line-numbers-mode 1)  ; show line numbers
(show-paren-mode 1)         ; highlight matching parens
(electric-pair-mode 1)      ; auto-close brackets

;; Theme
(use-package doom-themes
  :config
  (setq doom-themes-enable-bold t
        doom-themes-enable-italic t)
  (load-theme 'doom-one t))

;; Editing
(setq-default tab-width 4)
(setq-default indent-tabs-mode nil)
(setq-default fill-column 80)
(global-auto-revert-mode t)  ; auto-reload changed files
(setq backup-directory-alist '(("." . "~/.emacs.d/backups")))
(setq auto-save-file-name-transforms '((".*" "~/.emacs.d/auto-save/" t)))

;; Key bindings
(global-set-key (kbd "C-<tab>") 'other-window)
(global-set-key (kbd "M-/") 'company-complete)
(global-set-key (kbd "C-c g") 'magit-status)
(global-set-key (kbd "C-x k") 'kill-current-buffer)
```text

### Common Packages

#### Magit (Git Interface)

```bash
# Install
M-x package-install RET magit RET

# Usage
C-x g         # open Magit status buffer
# In Magit status:
#   s = stage file
#   u = unstage file
#   c c = commit (opens commit message buffer)
#   C-c C-c = finish commit
#   P p = push
#   F p = pull
#   l l = log
#   d d = diff
#   z s = stash
#   b b = checkout branch
#   Tab = expand/collapse section
#   q = quit Magit
```text

#### Company (Auto-Completion)

```bash
# Install
M-x package-install RET company RET

# Configuration (add to init.el)
(use-package company
  :hook (prog-mode . company-mode)
  :config
  (setq company-minimum-prefix-length 1
        company-idle-delay 0.0)
  (global-company-mode 1))

# Usage (in prog-mode, completions appear automatically):
M-/           # trigger completion manually
C-n / C-p     # navigate completion candidates
Tab           # accept completion
```text

#### Flycheck (Syntax Checking)

```bash
# Install
M-x package-install RET flycheck RET

# Configuration (add to init.el)
(use-package flycheck
  :init (global-flycheck-mode))

# Usage:
# Flycheck runs automatically in supported modes
C-c ! l       # list errors
C-c ! n       # jump to next error
C-c ! p       # jump to previous error
C-c ! v       # verify Flycheck setup
C-c ! s       # set checker
```text

### Key Chord Reference

#### Essential Survival Keys

| Key | Action |
| --- | ------ |
| `C-g` | Cancel any command |
| `C-x C-c` | Quit Emacs |
| `C-x u` or `C-/` | Undo |
| `C-x C-f` | Open file |
| `C-x C-s` | Save file |
| `C-x C-b` | List buffers |
| `C-x b` | Switch buffer |

#### Movement

| Key | Action |
| --- | ------ |
| `C-f / C-b` | Char forward / back |
| `C-n / C-p` | Line down / up |
| `C-a / C-e` | Line start / end |
| `M-f / M-b` | Word forward / back |
| `M-< / M->` | Buffer start / end |
| `C-v / M-v` | Page down / up |

#### Killing & Yanking

| Key | Action |
| --- | ------ |
| `C-k` | Kill line (cut to end) |
| `C-w` | Kill region (cut selection) |
| `M-w` | Copy region |
| `C-y` | Yank (paste) |
| `M-y` | Cycle kill ring |

#### Window & Buffer

| Key | Action |
| --- | ------ |
| `C-x 2` | Split horizontal |
| `C-x 3` | Split vertical |
| `C-x 1` | Single window |
| `C-x o` | Other window |
| `C-x b` | Switch buffer |
| `C-x k` | Kill buffer |

#### Search & Replace

| Key | Action |
| --- | ------ |
| `C-s / C-r` | Search forward / backward |
| `M-%` | Query replace |
| `C-M-%` | Query replace regex |

#### Help System

```bash
C-h f         # describe function
C-h v         # describe variable
C-h k         # describe key binding
C-h m         # describe current mode's bindings
C-h a         # apropos (search all commands by keyword)
C-h t         # built-in Emacs tutorial
C-h i         # Info manual browser
```text

---

## Quick Comparison

| Feature | Vim | Nano | Emacs |
| ------- | --- | ---- | ----- |
| **Learning curve** | Steep | Minimal | Steep |
| **Modes** | Yes (modal) | No (modeless) | No (modifier keys) |
| **Config file** | `~/.vimrc` | `~/.nanorc` | `~/.emacs.d/init.el` |
| **Extensibility** | Vimscript / Lua | Limited | Emacs Lisp (infinite) |
| **Package manager** | Built-in + plugins | Syntax files only | Built-in ELPA/MELPA |
| **Mouse support** | Yes (`:set mouse=a`) | Yes (`-m` flag) | Yes (built-in) |
| **Best for** | Speed, SSH editing, scripting | Quick configs, beginners | Power users, full IDE, Org-Mode |
| **Startup time** | Very fast | Instant | Slower (loads packages) |
| **Built-in terminal** | `:terminal` | No | `M-x term` / `vterm` |
| **Built-in file manager** | `:Ex` (netrw) | No | Dired |
| **Git integration** | fugitive, vim-gitgutter | No | Magit (gold standard) |
| **LSP support** | coc.nvim, nvim-lsp | No | lsp-mode, eglot |

---

## Tips

### Emergency Vim: How to Exit

```bash
# If you're stuck in Vim, press Esc first, then:
:q!           # quit without saving
```text

### Vim: Recover from a Crash

```bash
# Vim creates swap files (.swp). If Vim crashed:
vim -r file.txt       # recover from swap file
# After recovery:
# :write to save, then delete the swap file
```text

### Nano: Enable Syntax Highlighting System-Wide

```bash
# Install Nano syntax files (Debian/Ubuntu)
sudo apt install nano-syntax-highlighting

# Enable all syntax highlighting for all users
echo "include /usr/share/nano/*.nanorc" | sudo tee -a /etc/nanorc
```text

### Emacs: Install Packages from MELPA

```bash
# Add MELPA to init.el (if not already present)
(add-to-list 'package-archives
             '("melpa" . "https://melpa.org/packages/") t)

# Then in Emacs:
M-x package-refresh-contents RET
M-x package-install RET <package-name> RET
```text

### Choosing the Right Editor

```bash
# Quick SSH config edit on a remote server
nano /etc/nginx/nginx.conf

# Rapid code editing in a terminal
vim main.py

# Full development environment with Org-Mode notes, Git, LSP
emacs
```text

---

## Next Steps

- [Bash CLI Tools Cheat Sheet](/devops/bash-tools-cheatsheet/) — Unix command-line utilities for power users
- [Git CLI Cheat Sheet](/devops/git-cheatsheet/) — Version control commands and workflows
- [Docker CLI Cheat Sheet](/devops/docker-cheatsheet/) — Container management reference
- [Markdown Cheat Sheet](/devops/markdown-cheatsheet/) — Formatting reference for documentation