Skip to content

Instantly share code, notes, and snippets.

@overture8
Last active December 19, 2015 23:08
Show Gist options
  • Save overture8/6032133 to your computer and use it in GitHub Desktop.
Save overture8/6032133 to your computer and use it in GitHub Desktop.
VIM demo

Introduction

  • What is vim (also known as VI)? - An Editor! Like Sublime, TextMate etc.

  • Show of hands for people who use vim:-

    • Every day? (Kind of expected)
    • Ocassionally? (First part boring)
    • Never? (Comfortable at the command-line?)
  • Format of this talk - [TOPIC, PRACTICAL FREESTYLE, TOPIC... etc]. Why PRACTICAL FREESTYLE TIME? Because I didn't get time to create some practical instructions. LEARNING IS IN DOING - ESPECIALLY WITH VIM.

  • What this talk is not

    • A vim vs. Sublime talk
    • A vim vs. TextMate talk
    • A vim vs. IDE talk
  • I want to show you how I use vim

  • Why do few people use vim?

    • Large barrier to entry
  • Why learn vim?... if it's so much pain

    • Get more done with less keystrokes
    • You want to reach for your mouse less!
    • Lightweight
    • Highly configurable and very powerful
  • I don't want this to put you off!, but learing VIM is a longterm commitment. To become an expert you need to be willing to learn a little bit more each day.

  • Use a Cheatsheet! You're not going to remember everything you learn here.

  • Let's get started:

    1. First off - Configure vim with my .vimrc setup.
    2. Then - Jump into learning the basics.

Configuration

  • Good news: You should already have vim installed!

VIM Setup Instructions

  • Talk about how vim is configured
  • Talk about how to backup configuration
  • Talk about how to install a new configuration from scratch
  • Talk about vim plugins
  • Talk about vundle
  • RE-ENABLE cursor keys??

Simple Start to explain modes

  • Open a new file (normal mode)
  • Add some text (insert mode)
  • Copy and paste some text (visual mode)
  • Save it (command mode)

Modes

  • Normal Mode (Explain)
  • Insert Mode (Explain)
  • Visual Mode (Explain)
  • Command-line Mode (Explain)

Elaborate on Insert Mode

  • i (move into insert mode on current character)
  • a (moves into insert mode and moves to next character)
  • o (moves into insert mode, creates a new line and moves cursor to it)
  • ESC (move you back to Normal mode)

[[ PRACTICAL FREESTYLE TIME ]]

Motions & Operators

Motions and Operators are performed in Normal mode.

  • h (left)
  • j (down)
  • k (up)
  • l (right)

Why? Hands on the home row.

  • Very hard to get use to - I wouldn't recommend it at the start because it heightens the barrier to entry.
  • Turn off the cursor keys if you really want it to sink in.

Other Motions

  • w (forward word)
  • b (back word)
  • $ (end of line)
  • ^ (start of line)

Numbers with Motions

  • 3w (forward three words)
  • 2b (back two words)

Operators

Here are a few:

  • d (delete)
  • c (change)
  • y (yank)

Combining Motions & Operators

  • dw (delete a word)
  • d3w (delete three words)
  • y3w (copy/yank three words)
  • cw (delete a word - deletes and puts into insert mode)
  • d$ (delete to end of line)

Special operations

  • dd (delete current line)

Now's a good time for a...

[[ PRACTICAL FREESTYLE TIME ]]

Text Objects

Pair Text Objects

  • i"
  • i(
  • i{

Word Text Objects

  • iw = Current Word
  • aw = Current Word plus one space

THESE ARE ONLY OF USE WHEN USED WITH AN OPERATOR

SO:

  • ci"
  • di(
  • viw

etc.

Navigating Your Project

  • :e
  • ctrlp Plugins
  • NERDtree plugin

Split Windows

  • :split
  • :vsplit

Seaching a file and a project

  • /
  • n (next match forwards)
  • N (next match backwards)

Useful Plugins

  • ctrlp

    • \l
    • to open in split window
  • nerdtree

    • :NERDtree
  • vim-rails

    • gf

    • :Emodel

    • :Eview

    • :Econtroller

    • :Smodel

    • :Sview

    • :Scontroller

  • vim-easymotion

    • \w
  • gundo

    • \u

Check out vimtutor!

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