Slide 1

Slide 1 text

Custom Motions in Vim Alex

Slide 2

Slide 2 text

Goals ‣ Revise

Slide 3

Slide 3 text

Motions move the cursor What

Slide 4

Slide 4 text

Custom Motions ‣ Motions

Slide 5

Slide 5 text

Vim’s Grammar [operator][count][motion] Change

Slide 6

Slide 6 text

Vim’s Grammar [operator][count][motion] d 2 w delete 2 words Wednesday, 30 January 13

Slide 7

Slide 7 text

Vim’s Grammar [operator][count][motion] Operator- Pending

Slide 8

Slide 8 text

Operator-Pending Mode ‣ Map

Slide 9

Slide 9 text

Mappings ‣ Example:

Slide 10

Slide 10 text

Mappings " From: learnvimscriptthehardway.stevelosh.com/chapters/51.html function! s:NextSection(type, backwards) endfunction noremap <buffer> <silent> ]] :call <SID>NextSection(1, 0)<cr> noremap <script> <buffer> <silent> [[ :call <SID>NextSection(1, 1)<cr> noremap <script> <buffer> <silent> ][ :call <SID>NextSection(2, 0)<cr> noremap <script> <buffer> <silent> [] :call <SID>NextSection(2, 1)<cr> Wednesday, 30 January 13

Slide 11

Slide 11 text

Mappings function! s:NextSection(type, backwards) if a:type == 1 let pattern = ... elseif a:type == 2 let pattern = ... endif if a:backwards let dir = '?' else let dir = '/' endif execute 'silent normal! ' . dir . pattern . "\r" endfunction Wednesday, 30 January 13

Slide 12

Slide 12 text

In the Wild ‣ Functions ‣ search() ‣ Keys

Slide 13

Slide 13 text

search() ‣ Regular

Slide 14

Slide 14 text

Another Example ‣ New! ‣ Like

Slide 15

Slide 15 text

The End omap search() noremap Wednesday, 30 January 13