Vim Basics

..and changing your life forever

Why Vim?

Because mice are lame and inefficient and we wield ultimate power and magic with our almighty keyboard.

How to install Vim?

Mac - Download latest macvim package

# Ubuntu / Debian
$ sudo apt-get update
$ sudo apt-get install vim-gnome

# Fedora / Red Hat
$ dnf -y update
$ dnf -y install vim-enhanced

# Arch Linux
$ sudo pacman -Sy
$ sudo pacman -S gvim

Linux - Use your distro package manager

We use vim-gnome variants for clipboard functionality by default

How to start Vim?

In any Mac or Linux environment with Vim installed  you can open Vim in several ways:

# To start vim with no file to open
$ vim

# To open a text file in vim
$ vim somefile.py

# To create a new text file and open it
# NOTE: File will not truly exist until you save inside vim
$ vim somefile.py

# To open a file in another location
$ vim /home/jaywon/code/magic/SpellCaster.js

Vim Modes

Normal Mode

Normal mode is the mode where you can navigate your cursor around the document without inserting any text with those key commands

Also known as Dora mode by vim l33t

Vim Modes

Insert Mode

The reality you've lived in so far in your text editing life. Insert mode has been YOUR normal mode until now.  

Vim Modes

Visual Mode

Visual mode is for more advanced features of editing a document to highlight and operate on larger sections of text.

Vim Modes

How Do I Know?

IIf you're ever not sure what mode you're in just look at your lower left hand corner of Vim.

Basic Commands

esc

When in doubt, don't freak out.....escape!!!

Basic (Normal Mode) Commands

Navigation

aka. Death of the Arrow Keys

h - move cursor left

j - move cursor down

k - move cursor up

l - move cursor right

You will see your cursor as a blinking box

Basic (Normal Mode) Commands

Word Navigation

w - jump to the next word (no special characters) 

W - jump to the next word (with special characters) 

b - jump to the previous word (no special characters) 

B - jump to the previous word (with special characters) 

e - jump to the end of the word (no special characters) 

E- jump to the end of the word (with special characters) 

[wWbB] - Go to start of word

[eE] - Go to end of word

Basic (Normal Mode) Commands

Power Move Navigation

0 - Go to beginning of line

$ - Go to end of line

gg - Go to beginning  of document

G - Go to end  of document

5gg or 5G - Go to line 5  of document

Ctrl + f - Go forward one page  of document

Ctrl + b - Go back one page  of document

Basic (Normal Mode) Commands

Saving Files / Exiting Vim

:w - Save changes to file - SAVE OFTEN

:x - Save changes to file and close the file

:q - Close file - Only works if there are no unsaved changes

:q! - Close file and don't save changes

u - Undo last change

Ctrl+r - Redo last change

Basic (Insert Mode) Commands

Where do I start typing?

i - Insert character before the cursor

I - Insert at the beginning of line

a- Insert one character after the cursor

A - Insert at end of line

o - Create a new line after cursor line for inserting

O - Create a new line before cursor line for inserting

esc - BAIL BAIL BAIL - BACK TO SAFETY(Normal Mode)

Basic (Visual Mode) Commands

Working with larger chunks of text

v - Start visual mode at the cursor and select text with navigation commands

V - Start visual mode in line mode aka. select the entire line

y - yank or copy the highlighted text

d - delete or cut highlighted text

p - put or paste yanked or deleted text after cursor

P - put or paste yanked or deleted text before cursor

References

Vim Cheat Sheet

http://vim.rtorr.com/

Vim Adventures - Practice Basic Commands

http://vim-adventures.com/​

$ vimtutor

Vim Tutor Command Line Practice

Jack's Lament - Practice Text Commands

$ curl -o jackslament.txt https://gist.github.com/jaywon/daf628da28c1a30c9f289a82d3e40350
$ vim jackslament.txt

Vim Basics

By Jason Sewell