/
quicklaunch.vim
84 lines (59 loc) · 1.99 KB
/
quicklaunch.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
" Launch the registered command in quickly.
" Version: 0.1.1
" Author : thinca <thinca+vim@gmail.com>
" License: Creative Commons Attribution 2.1 Japan License
" <http://creativecommons.org/licenses/by/2.1/jp/deed.en>
if exists('g:loaded_quicklaunch') || v:version < 702
finish
endif
let g:loaded_quicklaunch = 1
let s:save_cpo = &cpo
set cpo&vim
function! s:quicklaunch(no)
if !exists(':QuickRun')
echoerr ':QuickRun command is not defined.'
endif
if !exists('g:quicklaunch_commands[a:no]')
\ || type(g:quicklaunch_commands[a:no]) != type('')
\ || g:quicklaunch_commands[a:no] == ''
echoerr 'quicklaunch has no such command:' a:no
return
endif
execute 'QuickRun' '-exec' '"' . substitute(
\ g:quicklaunch_commands[a:no], '"', '\\"', 'g') . '"' '>'
endfunction
function! s:quicklaunch_list()
if !exists('g:quicklaunch_commands')
echo 'no command registered'
return
endif
for i in range(10)
echo i . ': ' . (exists('g:quicklaunch_commands[i]') ? g:quicklaunch_commands[i] : '<Nop>')
endfor
endfunction
function! s:define_interface_key_mappings()
for i in range(10)
execute 'nnoremap <silent> <Plug>(quicklaunch-' . i . ')'
\ ':<C-u>call <SID>quicklaunch(' . i . ')<CR>'
endfor
nnoremap <silent> <Plug>(quicklaunch-list)
\ :<C-u>QuickRun -exec ':call <SID>quicklaunch_list()' ><CR>
endfunction
function! s:define_default_key_mappings()
for i in range(10)
if !hasmapto('<Plug>(quicklaunch-' . i . ')', 'n')
execute 'silent! nmap <unique> <Leader>' . i
\ '<Plug>(quicklaunch-' . i . ')'
endif
endfor
if !hasmapto('<Plug>(quicklaunch-list)', 'n')
silent! nmap <unique> <Leader>l <Plug>(quicklaunch-list)
endif
endfunction
call s:define_interface_key_mappings()
if !exists('g:quicklaunch_no_default_key_mappings')
\ || !g:quicklaunch_no_default_key_mappings
call s:define_default_key_mappings()
endif
let &cpo = s:save_cpo
unlet s:save_cpo