VI
1. Navigation
0: Move to the start of the line99 + RightArrow: Move to the end of the linegg: Jump to the top of the fileShift + g: Jump to the bottom of the filew: Move to the start of the next worde: Move to the end of the current wordb: Move to the beginning of the previous wordfx: Move to the next x character on the line (replace x);: Repeat last f, t, F, or T command
2. Editing
dd– Deletes (cut) the current linendd– Deletes n lines (e.g.,10dddeletes 10 lines from the current line downward)dG– Deletes from the current line to the end of the filedgg– Deletes from the current line to the beginning of the file- Visual Mode: Press
Vto enter visual line mode, then use the arrow keys to select multiple lines, then pressdto delete them Shift + c– Deletes everything to rhe right, and puts you in insert modeu– Undo last changeCtrl + r– Redo last changeShift + j– Join the current line with the next oneyy– Yank (copy) the current linep– Paste after cursorShift + p– Paste before cursorcw– Change word (deletes the word from where the cursor is and to the right and puts you in insert mode)
3. Visual Mode
Visual mode allows you to select text before performing operations on it. This is useful for deleting, copying, or modifying multiple lines or blocks of text.
Entering Visual Mode:
v– Start visual selection (characterwise) - selects character by characterV– Start visual line selection - selects entire linesCtrl + v– Start visual block selection (column mode) - very powerful for column editing
Navigation in Visual Mode:
- Use arrow keys to extend your selection
- Use
$to select to end of line,0to select to start of line - Use
ggorGto select to top/bottom of file - Use
w,e,bto select by words
Operations on Selected Text:
dorx– Delete (cut) the selected texty– Yank (copy) the selected textc– Change (delete and enter insert mode)>– Indent selected lines to the right<– Indent selected lines to the left~– Toggle case of selected charactersu– Make selected text lowercaseU– Make selected text uppercase
4. Search and Replace
/word– Search forward for "word"?word– Search backward for "word"n– Go to next matchShift + n– Go to previous match:%s/foo/bar/g– Replace all occurrences of "foo" with "bar" in the file
- 💡 Pro Tip: Use
.to repeat your last editing command