- Vim motions consist of modes and commands that help developers navigate and edit code more efficiently.
- Vim comes with three modes:
- Normal Mode: Where you type all the Vim commands.
- Insert Mode: Where you actually write code.
- Visual Mode: Helps us visually select and manipulate text.
- Normal Visual Mode: Works like selecting text with a mouse.
- Block Visual Mode: Helps you select text as a block.
h,j,k,l: Move left, down, up, rightw,b,e: Navigate forward word by word, backward word by word, jump to the end of a word0,^,$: Jump to the beginning of the line, first non-empty character, end of the linef<character>,F<character>: Jump to the next/previous occurrence of<character>on the line(,): Move one sentence up/down{,}: Move one paragraph up/downCtrl + d,Ctrl + u: Move down/up half a pageCtrl + f,Ctrl + b: Move down/up a full pagegg,G: Move to the top/bottom of the file
:w: Save the current file:set number,:set nonumber: Show/hide line numbers
i,a: Insert text before/after the cursorI,A: Insert text at the beginning/end of the lineo,O: Insert a new line below/above the current linec,s: Change the current word or selected text / Replace the current character and enter insert mode
y,p: Yank (copy) selected text / Paste yanked textyy: Yank the entire lineyi{char},ya{char}: Yank text inside/including specified braces or quotes
u: Undo the last changeCtrl + r: Redo the undone change
d: Delete the current word, sentence, or paragraphdd: Delete the current linedt<character>: Delete up to a specific characterdw,ds,dp: Delete word / Delete sentence / Delete paragraph
/: Search forward for a word?: Search backward for a wordn,N: Jump to the next/previous search result*,#: Search forward/backward for the word under the cursor
m{a-z}: Set a mark with a specific letter'{mark},'': Jump to the mark / Toggle between the last two positions'.: Jump to the position of the last edit
.: Repeat the last command:q,:wq,:qa: Quit Vim / Save and quit Vim / Quit all files
:Explore: Opens the file explorer within Vim to navigate and open files.:w: Saves the current file.:q: Quits Vim. Use:q!to quit without saving.:wq: Saves the file and quits Vim.:e <filename>: Opens the specified file in Vim.:vsp <filename>: Opens the specified file in a vertical split.:sp <filename>: Opens the specified file in a horizontal split.:tabnew <filename>: Opens the specified file in a new tab.:bd: Closes the current buffer (file).:set number: Displays line numbers.:set relativenumber: Displays relative line numbers.:set syntax=<syntax>: Enables syntax highlighting for a specific language.:noh: Clears search highlighting.:%s/<old>/<new>/g: Replaces all occurrences of<old>with<new>in the file.:!<command>: Runs an external shell command from within Vim.:help <command>: Opens help documentation for the specified command.