cheatsheets/vimscript-snippets.md

41 lines
756 B
Markdown
Raw Permalink Normal View History

2015-05-05 16:00:33 +00:00
---
title: Vimscript snippets
2015-11-24 04:48:01 +00:00
category: Vim
2015-05-05 16:00:33 +00:00
---
### Bind function to key and command
command! YoFunctionHere call s:YoFunctionHere()
nnoremap <silent> x :call <SID>FunctionHere()<CR>
function! s:FunctionHere()
endfunction
2015-05-29 18:11:28 +00:00
### Call a function in insert mode
2015-10-04 20:28:42 +00:00
inoremap X <C-R>=script#myfunction()<CR>
2015-05-29 18:11:28 +00:00
inoremap <F2> <C-R>=MyVimFunc()?'':''<CR>
### Checking plugins
if globpath(&rtp, "plugin/commentary.vim") != ""
## Autoload
" autoload/hello.vim
if exists("g:hello_loaded") | finish | endif
let g:hello_loaded=1
function hello#method()
endfunction
" calling hello#method() will load only if autoload()
2015-05-05 16:00:33 +00:00
## Misc
### Version check
if version < 704
echom "requires vim >= 7.4"
endif