Introduction to Vim, the text editor

Post on 20-Jul-2015

396 views 1 download

transcript

Vim

The story of a Vimmerby Vysakh Sreenivasan

(vysakh0)

That tweet was a lie

Ooops

Vim learning curve is a mythI will tell you why

Still a better story than Word

A quick tutorial for Vim

Open up your terminal and type

vimtutor

written on Vim covering everything

That you could read in your free time

The exhaustive book ever

Open up your Vim

Press esc :h

When you want to type

Insert mode

For everything else. We will see that

Command mode

SuperMan inside the Vim editor

Lets get to the story of

He is in the middle of a street

Superman a.k.a the current cursor in Vim

- 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

(a.k.a motions)

How superman moves

What superman sees around

j

k

h lb e

These are few positions in the file

$0

Cursor movements:

h j k l ⇒ left down up right

see :h k

File movements:gg first lineG last line

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

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

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

w 2wb2b

Actions (few)

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

action * motion

Superman applies action along motion

w 2wb2b

dw (delete a word)

[times] action motion

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

w 2wb2b

y0(yank till beginning of line)

0

#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

#2 Learn to apply actionwhile moving around

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

Shortcut - doing the action twice

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

:h text-objects

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

Vim treats these as objects

- 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”

di”(delete inside quotes)

(lets see few commands in this mode)

Ex mode

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

:g/cool/d

Delete all the lines which does not have a number.

:v/\d/d

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

:%s/cool/hot/g

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

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

Vim settings

(inside your Vim, will show numbers)

:set number

Create your own shortcuts

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

:map - dd

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

There are plenty of settings

(vim loads it on startup)

~/.vimrc

set number

set hlsearch “highlight search

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

~/.vimrc

Plenty of dotfiles in githubI learned primarily from those

(Few must have plugins)

Plugins

I use neobundle

#1 Good plugin manager

I use unite

#2 File searcher

I use neo-snipmate

#3 Snippets

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

#4 Syntax checker

Everybody uses Fugitive

#5 Git inside vim

I use nerdCommenter

#6 Quick commenting

Use vim-surround

#7 Surrounding operations

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

#8 VIM-RAILS

VIM-DISPATCH

#9 Run programs async

Easymotion or vim-sneak

#10 To quickly move in file

For a Vim++ editor

And wait for NeoVim

Vim is difficult

If someone says mastering