|
1 | | -# Vim zero to one |
| 1 | +# Vim zero to one |
| 2 | + |
| 3 | +No matter if you're a DevOps engineer, developer, or Linux enthusiast, knowing Vim helps you navigate and edit files efficiently from the terminal—especially when working on remote servers where GUI editors aren’t available. |
| 4 | + |
| 5 | +This cheat sheet will help you get started and become productive with Vim 👇 |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## 🧠 What is Vim? |
| 10 | + |
| 11 | +Vim (Vi IMproved) is a highly configurable terminal-based text editor used for efficient text editing. It comes pre-installed on most UNIX systems. |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +## 🚀 Opening and Exiting Vim |
| 16 | + |
| 17 | +| Command | Description | |
| 18 | +|--------|-------------| |
| 19 | +| `vim filename` | Open file in Vim | |
| 20 | +| `:q` | Quit (only if no changes) | |
| 21 | +| `:q!` | Quit without saving | |
| 22 | +| `:w` | Save file | |
| 23 | +| `:wq` or `ZZ` | Save and quit | |
| 24 | +| `:x` | Save and quit (same as `:wq`) | |
| 25 | + |
| 26 | +--- |
| 27 | + |
| 28 | +## ✍️ Basic Modes |
| 29 | + |
| 30 | +| Mode | Description | |
| 31 | +|------|-------------| |
| 32 | +| `Normal` | Default mode (for navigation and commands) | |
| 33 | +| `Insert` | Press `i`, `I`, `a`, `A`, `o`, or `O` to enter | |
| 34 | +| `Visual` | Use `v`, `V`, or `Ctrl+v` to select text | |
| 35 | +| `Command-line` | Use `:` to enter commands | |
| 36 | + |
| 37 | +Press `Esc` anytime to return to **Normal mode**. |
| 38 | + |
| 39 | +--- |
| 40 | + |
| 41 | +## 🔡 Insert Mode Shortcuts |
| 42 | + |
| 43 | +| Key | Description | |
| 44 | +|-----|-------------| |
| 45 | +| `i` | Insert before cursor | |
| 46 | +| `I` | Insert at the beginning of the line | |
| 47 | +| `a` | Insert after cursor | |
| 48 | +| `A` | Insert at the end of the line | |
| 49 | +| `o` | Open new line below | |
| 50 | +| `O` | Open new line above | |
| 51 | + |
| 52 | +--- |
| 53 | + |
| 54 | +## 🎯 Navigation |
| 55 | + |
| 56 | +| Key | Description | |
| 57 | +|-----|-------------| |
| 58 | +| `h`, `j`, `k`, `l` | Move left, down, up, right | |
| 59 | +| `w`, `W` | Jump by word | |
| 60 | +| `b`, `B` | Jump back by word | |
| 61 | +| `0` | Start of line | |
| 62 | +| `^` | First non-blank character of line | |
| 63 | +| `$` | End of line | |
| 64 | +| `gg` | Go to beginning of file | |
| 65 | +| `G` | Go to end of file | |
| 66 | +| `:n` | Go to line number `n` | |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## 📋 Copy, Paste, Delete |
| 71 | + |
| 72 | +| Command | Action | |
| 73 | +|---------|--------| |
| 74 | +| `yy` | Yank (copy) line | |
| 75 | +| `dd` | Delete line | |
| 76 | +| `p` | Paste below | |
| 77 | +| `P` | Paste above | |
| 78 | +| `x` | Delete character | |
| 79 | +| `u` | Undo | |
| 80 | +| `Ctrl+r` | Redo | |
| 81 | + |
| 82 | +--- |
| 83 | + |
| 84 | +## 🔍 Searching |
| 85 | + |
| 86 | +| Command | Description | |
| 87 | +|---------|-------------| |
| 88 | +| `/word` | Search forward | |
| 89 | +| `?word` | Search backward | |
| 90 | +| `n` | Repeat search forward | |
| 91 | +| `N` | Repeat search backward | |
| 92 | + |
| 93 | +--- |
| 94 | + |
| 95 | +## 🛠️ Replace |
| 96 | + |
| 97 | +| Command | Description | |
| 98 | +|---------|-------------| |
| 99 | +| `r<char>` | Replace one character | |
| 100 | +| `R` | Enter replace mode | |
| 101 | +| `:%s/old/new/g` | Replace all in file | |
| 102 | +| `:s/old/new/g` | Replace all in current line | |
| 103 | + |
| 104 | +--- |
| 105 | + |
| 106 | +## 📁 Working with Files |
| 107 | + |
| 108 | +| Command | Description | |
| 109 | +|---------|-------------| |
| 110 | +| `:e filename` | Open another file | |
| 111 | +| `:ls` | List open buffers | |
| 112 | +| `:b2` | Switch to buffer 2 | |
| 113 | +| `:w newfile` | Save as new file | |
| 114 | + |
| 115 | +--- |
| 116 | + |
| 117 | +## 🧩 Plugins (Optional) |
| 118 | + |
| 119 | +Use a plugin manager like `vim-plug` to extend Vim: |
| 120 | + |
| 121 | +```vim |
| 122 | +call plug#begin('~/.vim/plugged') |
| 123 | +Plug 'preservim/nerdtree' " File explorer |
| 124 | +Plug 'junegunn/fzf.vim' " Fuzzy finder |
| 125 | +call plug#end() |
| 126 | +``` |
| 127 | + |
| 128 | +--- |
| 129 | + |
| 130 | +## 📚 Resources |
| 131 | + |
| 132 | +- [Vim Official Website](https://www.vim.org) |
| 133 | +- [Interactive Tutorial](https://www.openvim.com) |
| 134 | +- [Cheat Sheet](https://vim.rtorr.com) |
| 135 | +- `:help` in Vim to access built-in documentation |
0 commit comments