forked from b4winckler/vim
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsnake.vim
56 lines (47 loc) · 1004 Bytes
/
snake.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
if has('event_loop')
set nocompatible
set nocursorline
python << EOF
import sys
sys.path.append('.')
import snake
import vim
buf = vim.current.buffer
empty = ' ' * 80
buf[0] = empty
for n in xrange(20):
buf.append(empty)
EOF
function! Update()
python << EOF
snake.update()
EOF
endfunction
function! End()
unmap <buffer> k
unmap <buffer> j
unmap <buffer> h
unmap <buffer> l
unmap <buffer> <esc>
unmap <buffer> <space>
python << EOF
snake.end()
EOF
endfunction
function! KeyPress(k)
python << EOF
snake.keypress(vim.eval('a:k'))
EOF
endfunction
nnoremap <silent> <buffer> k :call KeyPress('up')<cr>
nnoremap <silent> <buffer> j :call KeyPress('down')<cr>
nnoremap <silent> <buffer> h :call KeyPress('left')<cr>
nnoremap <silent> <buffer> l :call KeyPress('right')<cr>
nnoremap <silent> <buffer> <esc> :call KeyPress('esc')<cr>
nnoremap <silent> <buffer> <space> :call KeyPress('space')<cr>
au User update-screen call Update()
au User end-game call End()
python << EOF
snake.start()
EOF
endif