OSDN Git Service

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