1
0
mirror of https://github.com/onkelbeh/cheatsheets.git synced 2025-06-14 22:27:33 +02:00
cheatsheets/vimscript-snippets.md
Rico Sta. Cruz 511de900ba
Formatting updates (#2133)
- Update some sheets which have very long sections
- Remove `layout: 2017/sheet` (everything has the same layout now)
- Remove outdated sheets
2024-04-03 18:30:24 +11:00

756 B

title category
Vimscript snippets Vim

Bind function to key and command

command! YoFunctionHere call s:YoFunctionHere()
nnoremap <silent> x :call <SID>FunctionHere()<CR>
function! s:FunctionHere()
endfunction

Call a function in insert mode

inoremap X <C-R>=script#myfunction()<CR>
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()

Misc

Version check

if version < 704
  echom "requires vim >= 7.4"
endif