Vi Story
1976 Bill Joy writes vi
The name vi stands for visual
vi-style editors are the most widely spread editors in the
UNIX world.
It is available on any UNIX system
Wednesday, October 12, 2011
Slide 3
Slide 3 text
Vim Story
First developed in 1991 by Bram Moolenaar as a vim
clone for Amiga
It has since changed acronym to vi improved
vim is free software licensed as “charityware”
Wednesday, October 12, 2011
Slide 4
Slide 4 text
Amiga
Where it all started
Wednesday, October 12, 2011
Slide 5
Slide 5 text
Vim Advantages
Highly customizable
Works with many programming languages
Strong OS Integration
Scriptable
Wednesday, October 12, 2011
Slide 6
Slide 6 text
Meet Vim
gvim is the cross
platform graphics
version of vim
Wednesday, October 12, 2011
Slide 7
Slide 7 text
Modal Editing
Wednesday, October 12, 2011
Slide 8
Slide 8 text
Modal Editor
A modal editor changes the meaning of the keys in
each mode of operation
When using vim editor, we have 4 keyboards at our
disposal
Vim modes: normal, visual, insert, ex (command
prompt)
Wednesday, October 12, 2011
Slide 9
Slide 9 text
Normal Mode
Wednesday, October 12, 2011
Slide 10
Slide 10 text
Normal Mode
In normal mode, we can view and manipulate existing
text
Operations: move around the buffer, copy-paste, delete
lines, save, exit.
Wednesday, October 12, 2011
Slide 11
Slide 11 text
Normal Mode
In normal mode, every command takes the form:
[operates_on]
For example, 4dw means delete 4 words.
Not all commands take the operates on param
Wednesday, October 12, 2011
Slide 12
Slide 12 text
Normal Mode Commands
Useful commands - delete:
d (motion) - delete
D - delete until end of line
dd - delete complete line
x - delete a single character (del)
X - delete a single character (backspace)
Wednesday, October 12, 2011
Slide 13
Slide 13 text
Normal Mode Commands
Useful commands - Yanking (copy-paste):
y (motion) - yank
Y - yank till end of line
yy - yank entire line
p - paste text after cursor
P - paste text before cursor
Wednesday, October 12, 2011
Slide 14
Slide 14 text
Normal Mode Commands
Undo/Redo:
u - undo
(hold down control and press r) - redo
Wednesday, October 12, 2011
Slide 15
Slide 15 text
Normal Mode Lab
Start vim on existing file
Delete the first line
Move the next 4 lines to the end of the file
Save and quit (use ZZ)
Wednesday, October 12, 2011
Slide 16
Slide 16 text
Insert Mode
Wednesday, October 12, 2011
Slide 17
Slide 17 text
Insert Mode
Keys we type represent text to be inserted to the buffer
Use one of i,a,o,c to enter
Use key to get back to normal mode
Wednesday, October 12, 2011
Slide 18
Slide 18 text
Normal -> Insert
i - keep cursor position
a - move cursor to the next character
o - move cursor to the next line
I - move cursor to beginning of line
A - move cursor to end of line
Wednesday, October 12, 2011
Slide 19
Slide 19 text
Insert Mode Lab
Start vim on existing file
Delete first paragraph
Write a new first paragraph telling 5 things you love
about vim
Save and Quit (from normal mode)
Wednesday, October 12, 2011
Slide 20
Slide 20 text
Ex Mode
Wednesday, October 12, 2011
Slide 21
Slide 21 text
Extended Mode
The :ex mode is vim’s command prompt
Pressing : in normal mode takes you there
Many commands have both ex versions and normal
version
Wednesday, October 12, 2011
Slide 22
Slide 22 text
Ex Mode Commands
:q - close window
:w filename - save as
:wq - save and exit
:e - open a file for editing
:r filename - read file and paste its content into current
buffer
:r !cmd - run unix command and paste its output into
current buffer
Wednesday, October 12, 2011
Slide 23
Slide 23 text
Ex Mode Commands
vim keeps its own current working directory. Can read
and change using:
:cd, :pwd
!cmd - run a unix command
!cmd % - run a unix command on current file
Wednesday, October 12, 2011
Slide 24
Slide 24 text
Ex Mode Commands
Try the following:
:!ls
:%!ls
:pwd
:e .
Wednesday, October 12, 2011
Slide 25
Slide 25 text
Visual Mode
Wednesday, October 12, 2011
Slide 26
Slide 26 text
Visual Mode Commands
Enter visual mode using v, V,
v - enter visual mode selecting characters
V - enter visual mode selecting lines
- enter visual mode selecting blocks
Wednesday, October 12, 2011
Slide 27
Slide 27 text
Visual Mode Commands
In visual mode, commands will operate on selected text
Try selecting some text and press d, y, p, ~
Wednesday, October 12, 2011
Slide 28
Slide 28 text
:help
Vim has a manual for
every topic
Try the following:
:help del
:help edit
:help 42
Wednesday, October 12, 2011
Slide 29
Slide 29 text
Editing Multiple FIles
Each window in vim displays a buffer
Multiple buffers can be opened at the same time
Window can switch active buffer
Wednesday, October 12, 2011
Slide 30
Slide 30 text
Working With Buffers
:ls - show open buffers
:b[id], :b name - move to buffer by id/name
:bp, :bn - move to next/previous buffer
:bd - close current buffer
Wednesday, October 12, 2011
Slide 31
Slide 31 text
Q & A
Wednesday, October 12, 2011
Slide 32
Slide 32 text
Customizing Vim
Wednesday, October 12, 2011
Slide 33
Slide 33 text
.vimrc file
On vim startup, it looks for a .vimrc file in the user’s
home directory
If such a file exists, every line is executed
Next are some useful .vimrc commands
Wednesday, October 12, 2011
Slide 34
Slide 34 text
Line
Numbers
set number
Wednesday, October 12, 2011
Slide 35
Slide 35 text
.vimrc
set ic “ignore case when searching”
set guifont=Courier\ 14
Wednesday, October 12, 2011
Slide 36
Slide 36 text
Key Bindings
Vim lets us map any key sequence to any action
map binds a key in all modes
imap binds a key in insert mode
cmap binds a key in command line (ex) mode
nmap binds a key in normal mode
vmap binds a key in visual mode
Wednesday, October 12, 2011
Slide 37
Slide 37 text
Key Bindings
Bind C-s to the key sequence , :w, enter, and
then back to insert mode
:imap :wa
Wednesday, October 12, 2011
Slide 38
Slide 38 text
Key Bindings ala Windows
vmap y
imap p
Wednesday, October 12, 2011
Slide 39
Slide 39 text
Key Bindings ala Windows
Open a new file dialog
nmap :browse confirm e
Open a save as dialog
map :browse confirm saveas
Wednesday, October 12, 2011
Slide 40
Slide 40 text
Q & A
Wednesday, October 12, 2011
Slide 41
Slide 41 text
Vim Plugins
Provide extra functionality in vim
Usually written in vimscript
There’s a plugin for that
Wednesday, October 12, 2011
Slide 42
Slide 42 text
Where To Find
http://vim-scripts.org/vim/scripts.html
http://www.vim.org/scripts/index.php
dedicated github repositories
Wednesday, October 12, 2011
Slide 43
Slide 43 text
DEMO - Installing
A Plugin
Wednesday, October 12, 2011
Slide 44
Slide 44 text
Recommended Plugins
NERDTree
Surround
Align
Command-T
NERDCommenter
Also worth checking: janus, vundle
Wednesday, October 12, 2011
Slide 45
Slide 45 text
Thank You
Ynon Perek
[email protected]
ynonperek.com
Wednesday, October 12, 2011