OSDN Git Service

Regular updates
[twpd/master.git] / vimscript-snippets.md
1 ---
2 title: Vimscript snippets
3 category: Vim
4 ---
5
6 ### Bind function to key and command
7
8     command! YoFunctionHere call s:YoFunctionHere()
9     nnoremap <silent> x :call <SID>FunctionHere()<CR>
10     function! s:FunctionHere()
11     endfunction
12
13 ### Call a function in insert mode
14
15     inoremap X <C-R>=script#myfunction()<CR>
16     inoremap <F2> <C-R>=MyVimFunc()?'':''<CR>
17
18 ### Checking plugins
19
20     if globpath(&rtp, "plugin/commentary.vim") != ""
21
22 ## Autoload
23
24     " autoload/hello.vim
25     if exists("g:hello_loaded") | finish | endif
26     let g:hello_loaded=1
27
28     function hello#method()
29     endfunction
30
31     " calling hello#method() will load only if autoload()
32
33 ## Misc
34
35 ### Version check
36
37     if version < 704
38       echom "requires vim >= 7.4"
39     endif
40