Eine kuratierte Sammlung praktischer Vimscript-Muster und Vorlagen für die Plugin-Entwicklung und Anpassung der vimrc.
Tasten- & Befehlsbelegungen
" Benutzerdefinierten Befehl an skriptlokale Funktion binden
command! YoFunctionHere call s:YoFunctionHere()
" Taste im Normalmodus lautlos zuweisen
nnoremap <silent> x :call <SID>FunctionHere()<CR>
function! s:FunctionHere()
" Implementierung
endfunction
Funktionen im Einfügemodus aufrufen
" Ausdrucksregister (=) zum Einfügen des Ergebnisses verwenden
inoremap X <C-R>=script#myfunction()<CR>
inoremap <F2> <C-R>=MyVimFunc()?'':''<CR>
Verfügbarkeit von Plugins prüfen
if globpath(&rtp, "plugin/commentary.vim") != ""
" Plugin Commentary ist installiert
endif
Autoloading
" autoload/hello.vim
if exists("g:hello_loaded") | finish | endif
let g:hello_loaded = 1
function! hello#method()
echo "Hallo von automatisch geladener Funktion!"
endfunction
Der Aufruf von hello#method() lädt und sourct autoload/hello.vim automatisch bei Bedarf.
Verschiedenes
Versionsprüfungen
if v:version < 704
echom "Dieses Plugin erfordert Vim >= 7.4"
finish
endif