cheatsheets:ubuntu_vi_cheat_sheet
Vi Cheat Sheet
| Insert Text | Delete Text | Change | |||
|---|---|---|---|---|---|
| i | Insert before cursor | x | Delete char to the right of cursor | cw | Change word |
| I | Insert before line | X | Delete character to the left of cursor | cc | Change line |
| a | Append after cursor | D | Delete to the end of the line | C | Change to end of line |
| A | Append after line | dd | Delete current line | r | Replace ie rc replace char with c |
| o | New line below current | 5dd | Delete 5 lines | R | Replace type over |
| O | New line above current | db | Delete previous word | s | Substitute 1 char with text |
| r | Replace one character | dnw | Delete n words | S | Substitute rest of line with text |
| r | Replace more characters | dw | Delete word to buffer | . | Repeat last change |
| Recover buffer | Undo Commands | Quit | |||
| p | Put buffer after cursor | u | Undo last change | wq! | Write (save) and quit |
| P | Put buffer before cursor | U | Undo all changes on line | q! | Quit dont write (save) |
| Buffer commands | Window motions | Parameters | |||
| yy | Yank (copy) line to buffer | <ctrl>+d | Scroll down (half a screen) | :set list | Show invisible characters |
| 2yy | Yank (copy) 2 lines to buffer | <ctrl>+u | Scroll up (half a screen) | :set nolist | Don't show invisible characters |
| “z6yy | Yank 6 lines to buffer z | <ctrl>+f | Page forward | :set number | Show line numbers |
| yw | Yank a word to buffer | <ctrl>+b | Page backward | :set nonumber | Don't show line numbers |
| yaw | Yank word to byffer a | /string | Search forward | :set showmatch | Show matching sets of () |
| “a9dd | Delete 9 lines to buffer a | ?string | Search backward | :set noshowmatch | Don't Show matching sets of () |
| “A9dd | Delete 9 lines add to buffer a | n | Repeat search | :set showmode | Display mode on last line |
| “ap | Paste buffer a after cursor | N | Repeat search reverse | :set noshowmode | Turn off showmode |
| J | Join lines | G | Go to last line | ||
| :n | Go to line n | ||||
| Search And Replace | |||||
| :[command]s/old_text/new_text/ Example :%s/foo/bar/g Replaces all instanses of foo with bar command options: . Current line n Line number n .+ m Current line plus m lines $ Last line /string/ A line that contains “string” % Entire file [addr1],[addr2] Specifies a range Examples: Replaces only the first entry of foo with bar in each of 11 lines start at the current line (.) and continue for the 10 that follow (.+10). :.,.+10s/foo/bar Removes the last character from every line. Use it if every line in the file ends with ^M as the result of a file transfer. Execute it when the cursor is on the first line of the file. :%s/.$// |
|||||
cheatsheets/ubuntu_vi_cheat_sheet.txt · Last modified: by 127.0.0.1