Een samengestelde verzameling praktische Vimscript-patronen en codefragmenten voor plugin-ontwikkeling en vimrc-aanpassing.
Toets- & Opdrachttoewijzingen
" Aangepaste gebruikersopdracht koppelen aan scriptlokale functie
command! YoFunctionHere call s:YoFunctionHere()
" Toets geruisloos toewijzen in normale modus
nnoremap <silent> x :call <SID>FunctionHere()<CR>
function! s:FunctionHere()
" Implementatie
endfunction
Functies Aanroepen in Invoermodus
" Expressieregister (=) gebruiken om resultaat in te voegen
inoremap X <C-R>=script#myfunction()<CR>
inoremap <F2> <C-R>=MyVimFunc()?'':''<CR>
Beschikbaarheid van Plugins Controleren
if globpath(&rtp, "plugin/commentary.vim") != ""
" Commentary plugin is geïnstalleerd
endif
Automatisch Laden (Autoloading)
" autoload/hello.vim
if exists("g:hello_loaded") | finish | endif
let g:hello_loaded = 1
function! hello#method()
echo "Hallo vanuit automatisch geladen functie!"
endfunction
Het aanroepen van hello#method() laadt en doorzoekt autoload/hello.vim automatisch op aanvraag.
Diversen
Versiecontroles
if v:version < 704
echom "Deze plugin vereist Vim >= 7.4"
finish
endif