# Using Vim effectively

My current nvim setup vim preview

Vim is a very powerful text editor that makes manipulating text much easier and faster once it's commands are embedded into memory. The easiest way of understanding the core aspects of using vim would be to use it's built in tutorial. Run

:tutor
1

and complete it. Re-run it as many times as necessary.

# Normal Commands

  • i - insert mode
  • u - undo last
  • U - Undo line
  • dd - delete(and copy) line
  • p - paste
  • gg - move cursor to first line
  • 42G - move to start of line 42
  • dG - delete all lines
  • g=GG - indent all lines
  • gg"+yG - copy all lines (+: to system clipboard)
  • :%y+ - copy all lines (%: affect all lines`)

# Commands (invoked with :)

  • :q - quit
  • :q! - quit, discarding changes
  • :w - save
  • :wq - save and quit
  • :x - save and quit
  • :r !xsel -b - copy clipboard contents to file

To save a file (:w) that was opened as Read-only:

:w !sudo tee %
1

# Registers

  • :reg - view registers
  • ". - last entered text
  • "% - current file path
  • ": - most recently executed command