Mission vim possible

30
Mission Vim-Possible by Sam Gottfried

Transcript of Mission vim possible

Page 1: Mission vim possible

Mission Vim-Possibleby Sam Gottfried

Page 2: Mission vim possible

History of Vim

"In the beginning, there was ed. And ed begat ex; and ex begat vi; and vi begat vim."

Page 3: Mission vim possible

What is Vim?

● Vim is a highly customizable, highly efficient text editor

● Vim has several modes○ Normal ○ Insert○ Visual○ Ex mode

Page 4: Mission vim possible

Normal Mode

Normal Mode is the default mode in Vim.

You should spend most of your time in normal mode.

Page 5: Mission vim possible

Text Objects

a = a/ani = inside

aw -> a wordaW -> a WORD

as -> a sentence

ap -> a paragraph

Page 6: Mission vim possible

More Text Objects

a( -> a pair of parenthesis

a{ -> a pair of {braces}

a[ -> a pair of [brackets]

a< -> a pair of <angle brackets>

at -> a pair of XML tags

Page 7: Mission vim possible

More Text Objects

a" -> a pair of "quotes"a' -> a pair of 'quotes'

Examples:da" -> delete a pair of quotesci" -> change everything between the quotesyap -> yank a paragraph

Page 8: Mission vim possible

Motions

words vs WORDSdef foo(a,b)

word: [def][foo][(][a][,][b][)]WORD: [def][foo(a,b)]

w -> next word e -> end of wordW -> next WORD E -> end of WORD

b-> beginning of current wordB -> beginning of current WORD

Page 9: Mission vim possible

More Motions

f -> find a character F -> find a character (reverse)

t -> go to just before a characterT -> go to just after a character (reverse)

; -> next match (for f/F/t/T), -> previous match (for f/F/t/T)

Page 10: Mission vim possible

More Motions

/ -> search forward? -> search backwardsn -> next match (current direction)N -> previous match (current direction)

* -> search for word under the cursor# -> search backwards for word under the cursor

Page 11: Mission vim possible

Operator

y -> yankd -> deletec -> change

p -> paste (after)P -> paste (before)

Operator + motion = actiondw -> delete to the next word

Page 12: Mission vim possible

Line-wise operations

dd -> delete a linecc -> change a lineyy -> yank a line (copy)

>> -> shift right<< -> shift left== -> auto indent

Page 13: Mission vim possible

Counts

Most motions take a count3w -> move ahead 3 words5s -> move ahead 3 sentences

These can be combined with actions3dw -> delete a word 3 times (or d3w)5dd -> delete 5 lines2yy -> yank 2 lines

Page 14: Mission vim possible

Undo/Redo

Act, Repeat, Reverse

. -> repeat a changeu -> undo a change

- Chunk your Undos- Compose repeatable changes- Don't count if you can repeat

Page 15: Mission vim possible

Insert Mode

Entering Insert Modei -> insert to the left of the cursora -> insert to the right of the cursor (append)c -> change (usually combined with a motion)

I -> Insert at the beginning of the current lineA -> Append to the end of the current linecc -> change the current line

Page 16: Mission vim possible

Visual Mode

v -> character-wise Visual modeV -> line-wise Visual mode<C-v> -> block-wise Visual modegv -> re-selects last visual selection

You can switch between these without going into normal mode

Page 17: Mission vim possible

Ex mode

: -> enter Ex commandQ -> enter Ex mode (:visual to get out)

:[range]d[elete] -> deletes specified lines:[range]y[ank] -> yanks specified lines:[line]put -> puts the yanked lines under the current line

Page 18: Mission vim possible

Ex Mode Examples

:5 -> go to line 5:5p -> print line 5:$ -> go to last line:2,5p -> print lines 2-5:% -> the whole document:. -> the current line

Page 19: Mission vim possible

Registers

Use registers with yanks and deletesIncrease your clipboard size to 27!

"[register][count]action text object

example:"ayiw => Yank current word into register a"ap => Paste from register a

Page 20: Mission vim possible

Macros

Record a sequence of changes and then play them back

q{register} -> record a macro into a registerqa -> start recording a macro into register a

Press q again to stop the recording@{register} -> playback the macro in {register}

Page 21: Mission vim possible

Linewise Motions

0 -> go to beginning of a line^ -> first non-whitespace character of a line

$ -> end of line

Page 22: Mission vim possible

Macro Tips

Macros can be done in series

Macros can also be done in parallel

Macros are useful with counts (Dot command doesn't accept counts)

Page 23: Mission vim possible

Plugins

Tim Pope's Pathogen - Plugin Managergithub.com/tpope/vim-pathogen

Vim-Railsgithub.com/tpope/vim-rails

Ruby-Testgithub.com/janx/vim-rubytest

Page 24: Mission vim possible

More Plugins

NERDTree -> File tree explorergithub.com/scrooloose/nerdtree

Fugitive -> Git from within Vimgithub.com/tpope/vim-fugitive

Greplace -> Project search and replacegithub.com/skwp/greplace.vim

Page 25: Mission vim possible

More Plugins

Ack.vim -> Search project with Ackgithub.com/mileszs/ack.vim

Ultisnips -> Textmate-like snippetsgithub.com/SirVer/ultisnips

Ctrlp -> Fuzzy find filesgithub.com/kien/ctrlp.vim

Page 26: Mission vim possible

More Plugins

Supertab -> Easier autocompletegithub.com/ervandew/supertab

Page 27: Mission vim possible

Vimrc

Configuration for Vim

Page 28: Mission vim possible

Resources

vimtutor

:help <topic>

Practical Vim (from pragmatic bookshelf)

Vimcasts (http://vimcasts.org)

Page 29: Mission vim possible

Sam Gottfried

[email protected]

github.com/sgottfried

Twitter: @sam_gottfried

Page 30: Mission vim possible