Vim
the final text editor you need to learn
!
⾼高⾒見⻯⿓龍
Slide 2
Slide 2 text
No content
Slide 3
Slide 3 text
Current Status
80% iOS app, 20% Ruby/Rails
Slide 4
Slide 4 text
Scenario
Slide 5
Slide 5 text
I'm looking for a text editor..
Slide 6
Slide 6 text
1. launch quickly
2. easy to navigate between files
3. and pretty syntax highlight
Slide 7
Slide 7 text
Vim
Slide 8
Slide 8 text
Vim = Vi iMproved
Slide 9
Slide 9 text
Free and Charity
Slide 10
Slide 10 text
What's Vim?
Slide 11
Slide 11 text
it may look a little old-fashioned
Slide 12
Slide 12 text
but it can also be modern : )
Slide 13
Slide 13 text
So, Why Vim?
Slide 14
Slide 14 text
Keyboard-driven
Slide 15
Slide 15 text
Keyboard is King!
Slide 16
Slide 16 text
and, Why not Vim?
Slide 17
Slide 17 text
seems very hard to learn..
Slide 18
Slide 18 text
you won’t use other editors after learning
Vim..
Slide 19
Slide 19 text
Today, we have 2 Goals..
Slide 20
Slide 20 text
no Mouse
Slide 21
Slide 21 text
no Arrow keys
Slide 22
Slide 22 text
muscle memory
Slide 23
Slide 23 text
Tips
Slide 24
Slide 24 text
in terminal:
1. ctrl + z to stash vim, and type fg to bring it back.
2. ctrl + w to delete a word, ctrl + u to delete a whole
line, both work in terminal and vim edit mode.
3. ctrl + r to find history commands fuzzily.
Slide 25
Slide 25 text
How to Vim?
Slide 26
Slide 26 text
Practice:
Install Vim in your machine.
http://www.vim.org/download.php
Slide 27
Slide 27 text
:help
Slide 28
Slide 28 text
Modes
normal, visual, and edit mode
Slide 29
Slide 29 text
Modes Switch:
1. in normal mode, i or a or o to enter edit mode(i =
insert, a = append, o = newline)
2. in edit mode, ESC or Ctrl+[ to enter normal mode
3. in normal mode, hit v or V to enter visual mode
4. in visual mode, hit ESC or Ctrl+[ to normal mode
Slide 30
Slide 30 text
ESC or Ctrl + [
Slide 31
Slide 31 text
No content
Slide 32
Slide 32 text
Practice:
launch Vim and switch between normal,
visual, and edit mode.
Slide 33
Slide 33 text
Movement
:h movement
Slide 34
Slide 34 text
move cursor with h, j, k and l
disable arrow keys if possible
Slide 35
Slide 35 text
photo by Kent-Chen
Slide 36
Slide 36 text
Practice:
Use h, j, k, l instead of using arrow keys.
Slide 37
Slide 37 text
http://vim-adventures.com/
Slide 38
Slide 38 text
✓w or W to move cursor forward by a word, and b
or B is backward.
✓0 (number zero) to back to the begin of the line,
and $ is jump to the end.
✓fx will stop the cursor at the next "x" character in
current line, and F is search backward.
Slide 39
Slide 39 text
✓} will move cursor to next section, { move to last
section.
✓gg will move the cursor to the top of the current
file, and G will jump to bottom.
Slide 40
Slide 40 text
Practice:
Use word jumpers (b, w, fx..etc) to move
cursor between words and lines.
Slide 41
Slide 41 text
✓zz, zb, zt
✓/ search, n can jump to next matched result, and N
will jump to last one.
✓* search the word on cursor.
Slide 42
Slide 42 text
Practice:
search some keywords in your document.
Slide 43
Slide 43 text
Visual Selection
Slide 44
Slide 44 text
✓vit will visually select content between the tag,
while vat will even including the tag.
✓vi" will visually select content between current
double quotes.
✓viw will select the current word.
✓ctrl+v to enter block selection mode.
Slide 45
Slide 45 text
Basic
Slide 46
Slide 46 text
✓:w write to file.
✓:q exit Vim.
✓:tabe create a new tab.
✓gt to switch to next tab, gT to previous tab. (I
map gt and gT to F7 and F8 in my vimrc)
✓:new to create a horizontal split window, :vnew
or :vs to create a vertical split window.
Slide 47
Slide 47 text
✓vi -o a.rb b.rb to open those two files at the same
time with horizontal split window.
✓vi -O a.rb b.rb same as above, but in vertical split
window.
✓vi -p a.rb b.rb to open files with tabs.
✓vi http://www.eddie.com.tw will read the source
content into vim directly.
Slide 48
Slide 48 text
Practice:
1. quit Vim, and launch Vim, quite Vim, and
launch Vim .. x N
2. open a file with Vim, exit, then open it
again, then exit .. x N
Slide 49
Slide 49 text
Buffers
:ls, :bd, :b3, :b filename, :tab ba
Slide 50
Slide 50 text
Practice:
try to open several files, and switch between
them with buffer commands.
Slide 51
Slide 51 text
Vim Text Objects
Slide 52
Slide 52 text
d 3 w = delete 3 words
Slide 53
Slide 53 text
Word:
1. aw - around word
2. iw - inner word
Slide 54
Slide 54 text
Practice:
1. select a word, deselect, and select another word, and
deselect.. x N
!
2. select a word, delete it, select another word, and
delete.. X N
Slide 55
Slide 55 text
Sentence:
1. as - a sentence
2. is - inner sentence
Slide 56
Slide 56 text
Practice:
1. select a sentence, deselect, and select another
sentence, and deselect.. x N
!
2. select a sentence, delete it, select another sentence,
and delete.. X N
Slide 57
Slide 57 text
Paragraph:
1. ap - a paragraph
2. ip - inner paragraph
Slide 58
Slide 58 text
Practice:
1. select a paragraph, deselect, and select another
paragraph, and deselect.. x N
!
2. select a paragraph, delete it, select another
paragraph, and delete.. X N
Slide 59
Slide 59 text
Folding
:h folds
Slide 60
Slide 60 text
Basic:
- zf to fold selected lines
- zd to un-fold selected lines
Slide 61
Slide 61 text
Practice:
fold several lines, and unfold them .. x N
Slide 62
Slide 62 text
Editing
Slide 63
Slide 63 text
✓D to clear all content of current line after the
cursor.
✓C like D, but enter insert mode.
dG will clear all content after the cursor, dgg will
clear all content before the cursor.
✓x remove a character.
✓. to repeat last action.
✓dd to delete whole line, 3dd to delete 3 lines.
✓u to undo, ctrl+r to redo.
Slide 64
Slide 64 text
Practice!
Slide 65
Slide 65 text
✓~ to toggle upper case and lower case.
✓:m+ to move current line to next line.
✓:m-2 to move current line to previous line.
✓>> to add indentation.
✓<< to reduce indentation.
✓= re-format, gg=G re-format whole file.
Slide 66
Slide 66 text
Practice!
Slide 67
Slide 67 text
✓yy yank the whole line of the cursor.
✓3yy yank 3 lines.
✓p paste content from register, 3p paster content
from register for 3 times.
Slide 68
Slide 68 text
Practice!
Slide 69
Slide 69 text
✓dw, diw to delete the word in the cursor.
✓cw, ciw same as above, but enter insert mode.
✓r to replace current character.
✓J to concatenate current line with next line, 3J
will concatenate next 3 lines.
✓> to add indentation, < to remove indentation.
Slide 70
Slide 70 text
.vimrc
Slide 71
Slide 71 text
✓ set history=1000 keep 1000 lines of command line
history.
✓ set undolevels=100
✓ set ruler show the cursor position all the time
✓ set autoread auto read when file is changed from
outside
✓ set cursorline
✓ set number
✓ set numberwidth=4
Slide 72
Slide 72 text
✓ set nobomb no BOM(Byte Order Mark)
✓ set clipboard+=unnamed
✓ set splitright always open vertical split window in the
right side.
✓ set splitbelow always open horizontal split window
below.
✓ set scrolloff=5 start scrolling when n lines away from
margins
✓ set showtabline=2 always show tab
Slide 73
Slide 73 text
✓ set synmaxcol=128
✓ set viminfo= disable .viminfo file
✓ filetype on enable filetype detection
✓ filetype indent on enable filetype-specific indenting
✓ filetype plugin on enable filetype-specific plugins
✓ syntax on syntax highlight
✓ set hlsearch search highlighting
✓ set incsearch incremental search
✓ set ignorecase ignore case when searching
Slide 74
Slide 74 text
✓ set nobackup no *~ backup files
✓ set noswapfile
✓ set nowritebackup
✓ set expandtab replace with spaces
✓ set softtabstop=2
✓ set shiftwidth=2
✓ set tabstop=2
Slide 75
Slide 75 text
to disable sound on errors…
✓ set visualbell
✓ set noerrorbells
✓ set t_vb=
✓ set tm=500
Slide 76
Slide 76 text
file encoding…
✓ set encoding=utf-8
✓ scriptencoding utf-8
Slide 77
Slide 77 text
ignore something…
✓ set wildignore+=*
.o,*
.obj,*
.pyc
✓ set wildignore+=*
.png,*
.jpg,*
.gif,*
.ico
✓ set wildignore+=*
.swf,*
.fla
✓ set wildignore+=*
.mp3,*
.mp4,*
.avi,*
.mkv
if you want to use my .vimrc
1. clone from my Github repo
2. cd to cloned repo and execute install script
3. make symbolic link for vim
4. done!
Slide 84
Slide 84 text
or if you trust me…
1. via curl:
sh <(curl -L https://github.com/kaochenlong/eddie-vim/raw/master/utils/install.sh)
!
2. via wget:
sh <(wget --no-check-certificate https://github.com/kaochenlong/eddie-vim/raw/master/utils/install.sh -O -)