Skip to content

Instantly share code, notes, and snippets.

@harishphk
Last active September 2, 2022 17:06
Show Gist options
  • Save harishphk/f0be89579b19f57428fa3c1ce357e934 to your computer and use it in GitHub Desktop.
Save harishphk/f0be89579b19f57428fa3c1ce357e934 to your computer and use it in GitHub Desktop.

Vim Commands

Files

  • vi filename.txt - Open a file
  • : - Enter Command Mode
  • u - Undo changes
  • ctrl+u - Redo Changes
  • :q - Quit Vim
  • :q! - Force quit vim without saving
  • :w - Save file
  • :wq - Save file and quit

Deleting lines

  • d4j - Delete 4 lines from current position including current position
  • d4k - Delete 4 lines before current position including current position
  • dd4 - Delete 4 lines

Moving Through lines

  • 0 - Start of the line
  • $ - End of the line
  • gg - Top of document
  • G - Bottom of document
  • 4j - Move to 4th line from current position
  • 4k - Move to 4the line before current position

Copy and Paste

  • yy - copy a line
  • p - paste a line

Search

  • :/hello - Serach hello and hit enter

  • n - move to Next match

  • N - move to Previous match

  • :%s/hello/helloworld/g - Search and replace hello with helloworld in all places

  • :%s/hello/helloworld/gc -- Search and replace hello with helloworld in all places by confirming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment