65
Vim

Introduction to Vim, the text editor

Embed Size (px)

Citation preview

Page 1: Introduction to Vim, the text editor

Vim

Page 2: Introduction to Vim, the text editor

The story of a Vimmerby Vysakh Sreenivasan

(vysakh0)

Page 3: Introduction to Vim, the text editor
Page 4: Introduction to Vim, the text editor

That tweet was a lie

Page 5: Introduction to Vim, the text editor

Ooops

Page 6: Introduction to Vim, the text editor

Vim learning curve is a mythI will tell you why

Page 7: Introduction to Vim, the text editor

Still a better story than Word

Page 8: Introduction to Vim, the text editor

A quick tutorial for Vim

Page 9: Introduction to Vim, the text editor

Open up your terminal and type

vimtutor

Page 10: Introduction to Vim, the text editor

written on Vim covering everything

That you could read in your free time

The exhaustive book ever

Page 11: Introduction to Vim, the text editor

Open up your Vim

Press esc :h

Page 12: Introduction to Vim, the text editor

When you want to type

Insert mode

Page 13: Introduction to Vim, the text editor

For everything else. We will see that

Command mode

Page 14: Introduction to Vim, the text editor

SuperMan inside the Vim editor

Lets get to the story of

Page 15: Introduction to Vim, the text editor

He is in the middle of a street

Superman a.k.a the current cursor in Vim

Page 16: Introduction to Vim, the text editor

- beginning of the street - end of the street- next street- previous street- any where in the location

Just by saying a word

He can move to the

Page 17: Introduction to Vim, the text editor

(a.k.a motions)

How superman moves

Page 18: Introduction to Vim, the text editor

What superman sees around

j

k

h lb e

These are few positions in the file

$0

Page 19: Introduction to Vim, the text editor

Cursor movements:

h j k l ⇒ left down up right

see :h k

Page 20: Introduction to Vim, the text editor

File movements:gg first lineG last line

Line movements:0 beginning of the line$ end of the line

Page 21: Introduction to Vim, the text editor

w word forwardb word backward( sentence forward) sentence backward{ paragraph forward} paragraph backward

Page 22: Introduction to Vim, the text editor

You can even make yourown marks in the file, and move to it

Page 23: Introduction to Vim, the text editor

w 2wb2b

Page 24: Introduction to Vim, the text editor
Page 25: Introduction to Vim, the text editor

Actions (few)

- Delete with d- Yank with y- Change with c

Page 26: Introduction to Vim, the text editor

action * motion

Superman applies action along motion

Page 27: Introduction to Vim, the text editor

w 2wb2b

dw (delete a word)

Page 28: Introduction to Vim, the text editor

[times] action motion

dw + dw => 2dw (delete two words)

Page 29: Introduction to Vim, the text editor

w 2wb2b

y0(yank till beginning of line)

0

Page 30: Introduction to Vim, the text editor

#1 Learn to move around- Just learn how to reach a particular

position in a file.

- Say, for eg: next paragraph or next line or start of the line.

- Find the motion keystroke

Page 31: Introduction to Vim, the text editor

#2 Learn to apply actionwhile moving around

Page 32: Introduction to Vim, the text editor

yy yanks (copies) the current linedd deletes the current linecc changes the current linegUgU upcase the current line

Shortcut - doing the action twice

Page 33: Introduction to Vim, the text editor

inside(i) the object or around(a) the object

:h text-objects

Page 34: Introduction to Vim, the text editor

wordsentenceparagraph“ “, ‘ ‘ quotes[], (), <> blockstags (html tags)

Vim treats these as objects

Page 35: Introduction to Vim, the text editor

- From the cursor position, you can say this entire thing inside quotes using i”

- From the cursor position, you can say this entire thing of quotes using a”

“This quote is an object”

Page 36: Introduction to Vim, the text editor

di”(delete inside quotes)

Page 37: Introduction to Vim, the text editor

(lets see few commands in this mode)

Ex mode

Page 38: Introduction to Vim, the text editor

Delete(globally) all the lines that has the word "cool".

:g/cool/d

Page 39: Introduction to Vim, the text editor

Delete all the lines which does not have a number.

:v/\d/d

Page 40: Introduction to Vim, the text editor

Substitute “cool” with hot in all the lines and places

:%s/cool/hot/g

Page 41: Introduction to Vim, the text editor

Substitute “cool” with hot in all the lines that has “weather”

:g/weather/s/cool/hot/g

Page 42: Introduction to Vim, the text editor

Vim settings

Page 43: Introduction to Vim, the text editor

(inside your Vim, will show numbers)

:set number

Page 44: Introduction to Vim, the text editor

Create your own shortcuts

Page 45: Introduction to Vim, the text editor

(now when you press “-”, it will delete line)

:map - dd

Page 46: Introduction to Vim, the text editor

If you want it in every file, you put in vimrc

There are plenty of settings

Page 47: Introduction to Vim, the text editor

(vim loads it on startup)

~/.vimrc

Page 48: Introduction to Vim, the text editor

set number

set hlsearch “highlight search

map - dd “just an eg, don’t!

~/.vimrc

Page 49: Introduction to Vim, the text editor

Plenty of dotfiles in githubI learned primarily from those

Page 50: Introduction to Vim, the text editor

(Few must have plugins)

Plugins

Page 51: Introduction to Vim, the text editor

I use neobundle

#1 Good plugin manager

Page 52: Introduction to Vim, the text editor

I use unite

#2 File searcher

Page 53: Introduction to Vim, the text editor

I use neo-snipmate

#3 Snippets

Page 54: Introduction to Vim, the text editor

I use syntastic along with reek, rubocop for checking ruby style and codesmell

#4 Syntax checker

Page 55: Introduction to Vim, the text editor

Everybody uses Fugitive

#5 Git inside vim

Page 56: Introduction to Vim, the text editor

I use nerdCommenter

#6 Quick commenting

Page 57: Introduction to Vim, the text editor

Use vim-surround

#7 Surrounding operations

Page 58: Introduction to Vim, the text editor

If you’re a Rails dev, must use it.

#8 VIM-RAILS

Page 59: Introduction to Vim, the text editor

VIM-DISPATCH

#9 Run programs async

Page 60: Introduction to Vim, the text editor

Easymotion or vim-sneak

#10 To quickly move in file

Page 61: Introduction to Vim, the text editor

For a Vim++ editor

And wait for NeoVim

Page 62: Introduction to Vim, the text editor

Vim is difficult

If someone says mastering

Page 63: Introduction to Vim, the text editor
Page 65: Introduction to Vim, the text editor