๐Ÿ“ Introduction

This post is primarily for my own use, containing Vim commands that I frequently use or am trying to learn and remember. It focuses on essential motions and navigation techniques to improve efficiency.

Note: This post changes and updates frequently.


๐Ÿ  Basics

Basic commands to get started with Vim.

  • i โ†’ Insert mode
  • ESC โ†’ Exit insert mode
  • :w โ†’ Save file
  • :q โ†’ Quit
  • :wq or ZZ โ†’ Save and quit
  • :q! โ†’ Quit without saving

๐Ÿ”„ Moving Around

Essential motions for navigating within a file efficiently.

  • h โ†’ Left
  • j โ†’ Down
  • k โ†’ Up
  • l โ†’ Right
  • 0 โ†’ Beginning of line
  • ^ โ†’ First non-blank character of line
  • $ โ†’ End of line
  • w โ†’ Next word
  • b โ†’ Previous word
  • e โ†’ End of word
  • gg โ†’ Go to start of file
  • G โ†’ Go to end of file
  • 5G โ†’ Go to line 5
  • Ctrl-d โ†’ Move down half a screen
  • Ctrl-u โ†’ Move up half a screen
  • Ctrl-f โ†’ Move forward one full screen
  • Ctrl-b โ†’ Move backward one full screen

๐Ÿ” Searching and Replacing

Commands to search within a file and replace text efficiently.

  • /pattern โ†’ Search forward
  • ?pattern โ†’ Search backward
  • n โ†’ Repeat last search forward
  • N โ†’ Repeat last search backward
  • :%s/old/new/g โ†’ Replace all old with new
  • :.,+3s/old/new/g โ†’ Replace in current and next 3 lines

๐Ÿ“‚ Working with Files

File management commands to open, navigate, and switch between files efficiently.

  • :e filename โ†’ Open file
  • :tabe filename โ†’ Open in a new tab
  • :sp filename โ†’ Open in a horizontal split
  • :vsp filename โ†’ Open in a vertical split
  • :ls โ†’ List open buffers
  • :bnext or :bn โ†’ Next buffer
  • :bprev or :bp โ†’ Previous buffer
  • :bd โ†’ Delete buffer

๐Ÿ“ Editing

Essential editing commands for modifying text quickly.

  • x โ†’ Delete character under cursor
  • dd โ†’ Delete (cut) current line
  • yy โ†’ Copy current line
  • p โ†’ Paste
  • u โ†’ Undo
  • Ctrl-r โ†’ Redo
  • V โ†’ Visual line selection
  • v โ†’ Visual character selection
  • y โ†’ Yank (copy)
  • d โ†’ Delete (cut)
  • c โ†’ Change (delete and enter insert mode)

๐ŸŽฏ Marks and Jumps

Marks allow you to bookmark positions in your file and jump between them easily.

  • โ†’ Jump back to last cursor position
  • '' โ†’ Jump back to last line
  • :marks โ†’ Show marks
  • mX โ†’ Mark position with X
  • 'X โ†’ Jump to mark X

โŒจ๏ธ Macros

Macros allow you to record and replay sequences of commands, helping with repetitive tasks.

  • qX โ†’ Start recording macro X
  • q โ†’ Stop recording
  • @X โ†’ Run macro X
  • @@ โ†’ Run last macro

๐Ÿš€ Miscellaneous

Various useful commands for enhancing workflow.

  • :noh โ†’ Remove search highlight
  • :set number โ†’ Show line numbers
  • :set relativenumber โ†’ Show relative line numbers
  • :set ignorecase โ†’ Case-insensitive search
  • :set smartcase โ†’ Case-sensitive when uppercase is used
  • Ctrl-g โ†’ Show file info

๐Ÿ“Œ Tip: Mastering these commands will make you lightning-fast in Vim!

Let me know if you’d like any additions or modifications! ๐Ÿš€