Created
January 4, 2011 13:44
-
-
Save h1mesuke/764778 to your computer and use it in GitHub Desktop.
Vim - My snippets for Vim script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Snippets for VimScript | |
include separator_vim.snip | |
snippet modeline | |
prev_word '^' | |
" vim: filetype=vim | |
#----------------------------------------------------------------------------- | |
# Abbrevs | |
snippet lo | |
&l:${1:option} | |
snippet max | |
max([${1:values}]) | |
snippet min | |
min([${1:values}]) | |
snippet sub | |
substitute(${1:str}, '${2:pat}', '${3:rep}', '${4:g}') | |
snippet sub1 | |
substitute(${1:str}, '${2:pat}', '${3:rep}', '') | |
snippet subg | |
alias gsub | |
substitute(${1:str}, '${2:pat}', '${3:rep}', 'g') | |
#----------------------------------------------------------------------------- | |
# Commands | |
snippet augroup | |
alias au | |
prev_word '^' | |
augroup ${1:Name} | |
autocmd! | |
autocmd ${0} | |
augroup END | |
snippet prefix | |
prev_word '^' | |
nnoremap [${1:prefix}] <Nop> | |
nmap ${2:key} [$1] | |
snippet scriptencoding | |
alias senc | |
prev_word '^' | |
scriptencoding utf-8 | |
${0} | |
scriptencoding | |
#----------------------------------------------------------------------------- | |
# Debug | |
snippet em | |
prev_word '^' | |
echomsg "${1}" | |
snippet p | |
prev_word '^' | |
echomsg "${1} = " . string($1) | |
snippet d | |
prev_word '^' | |
call s:print_debug("${1} = " . string($1)) | |
snippet in | |
prev_word '^' | |
call input("${1}") | |
snippet reltime | |
prev_word '^' | |
if has("reltime") | |
let start_time = reltime() | |
endif | |
if has("reltime") | |
let used_time = split(reltimestr(reltime(start_time)))[0] | |
echomsg "Finished in " . used_time . " seconds." | |
endif | |
#----------------------------------------------------------------------------- | |
# Keywords | |
snippet function | |
alias fu | |
prev_word '^' | |
function! ${1:Name}(${2}) | |
${0} | |
endfunction | |
snippet function_sid | |
alias fus | |
prev_word '^' | |
function! s:${1:name}(${2}) | |
${0} | |
endfunction | |
snippet function_test | |
alias fut | |
prev_word '^' | |
function! tc.test_${1:func}() | |
${0} | |
endfunction | |
snippet if | |
prev_word '^' | |
if ${1} | |
endif | |
snippet if_has | |
prev_word '^' | |
if has("${1:feature}") | |
${0} | |
endif | |
snippet if_autocmd | |
prev_word '^' | |
if has("autocmd") | |
${0} | |
endif | |
snippet elseif | |
alias ei | |
prev_word '^' | |
elseif${1} | |
snippet ife | |
prev_word '^' | |
if ${1} | |
else | |
${2} | |
endif | |
snippet for | |
prev_word '^' | |
for ${1:var} in ${2:list} | |
${0} | |
endfor | |
snippet for_dict | |
prev_word '^' | |
for [${1:key}, ${2:val}] in items(${3:dict}) | |
${0} | |
endfor | |
snippet for_keys | |
prev_word '^' | |
for ${1:var} in keys(${2:dict}) | |
${0} | |
endfor | |
snippet for_values | |
prev_word '^' | |
for ${1:var} in values(${2:dict}) | |
${0} | |
endfor | |
snippet for_range | |
prev_word '^' | |
for ${1:var} in range(${2:from}, ${3:to}) | |
${0} | |
endfor | |
snippet for_vargs | |
prev_word '^' | |
for ${1:var} in a:000 | |
${0} | |
endfor | |
snippet while | |
alias wh | |
prev_word '^' | |
while ${1} | |
endwhile | |
snippet while_1 | |
alias loop | |
prev_word '^' | |
while 1 | |
${0} | |
endwhile | |
snippet while_upto | |
prev_word '^' | |
let ${1:var} = ${2:start} | |
while $1 < ${3:end} | |
${0} | |
let $1 += 1 | |
endwhile | |
snippet while_downto | |
prev_word '^' | |
let ${1:var} = ${2:start} | |
while $1 >= ${3:end} | |
${0} | |
let $1 -= 1 | |
endwhile | |
snippet while_times | |
prev_word '^' | |
let ${1:var} = 0 | |
while $1 < ${2:times} | |
${0} | |
let $1 += 1 | |
endwhile | |
snippet each_buf | |
prev_word '^' | |
let nr = 1 | |
while nr <= bufnr('$') | |
let bufname = bufname(nr) | |
${0} | |
let nr += 1 | |
endwhile | |
snippet each_win | |
prev_word '^' | |
let nr = 1 | |
while nr <= winnr('$') | |
let bufname = bufname(winbufnr(nr)) | |
${0} | |
let nr += 1 | |
endwhile | |
snippet try | |
prev_word '^' | |
try | |
catch | |
finally | |
endtry | |
snippet catch_interrupt | |
prev_word '^' | |
catch /^Vim:Interrupt$/ | |
snippet catch_vim_errors | |
prev_word '^' | |
catch /^Vim\%((\a\+)\)\=:E/ | |
snippet catch_vim_error | |
prev_word '^' | |
catch /^Vim\%((\a\+)\)\=:E${1:errno}:/ | |
snippet catch_write_errors | |
prev_word '^' | |
catch /^Vim(write):/ | |
snippet throw_arg_error | |
prev_word '^' | |
throw "ArgumentError: wrong number of arguments (" . ${1:argc} . " for ${2:expect})" | |
#----------------------------------------------------------------------------- | |
# OOP | |
snippet class_method | |
alias cme | |
prev_word '^' | |
function! s:${1:Class}_class_${2:name}(${3:args}) dict | |
${0} | |
endfunction | |
call s:$1.class_define(s:sid, '$2') | |
snippet method | |
alias me | |
prev_word '^' | |
function! s:${1:Class}_${2:name}(${3:args}) dict | |
${0} | |
endfunction | |
call s:$1.bind(s:sid, '$2') | |
snippet sid | |
prev_word '^' | |
function! s:SID() | |
return matchstr(expand('<sfile>'), '<SNR>\d\+_') | |
endfunction | |
let s:sid = s:SID() | |
#----------------------------------------------------------------------------- | |
# Plugin | |
snippet global_variable | |
alias gvar | |
if !exists('g:${1:name}') | |
let g:$1 = ${2:value} | |
endif | |
#----------------------------------------------------------------------------- | |
# Templates | |
snippet template_header | |
prev_word '^' | |
"============================================================================= | |
" File : ${1:file}.vim | |
" Author : `g:template_user_login1` <`g:template_user_email`> | |
" Updated : `g:template_date()` | |
" Version : 0.0.1 | |
" License : MIT license {{{ | |
" | |
" Permission is hereby granted, free of charge, to any person obtaining | |
" a copy of this software and associated documentation files (the | |
" "Software"), to deal in the Software without restriction, including | |
" without limitation the rights to use, copy, modify, merge, publish, | |
" distribute, sublicense, and/or sell copies of the Software, and to | |
" permit persons to whom the Software is furnished to do so, subject to | |
" the following conditions: | |
" | |
" The above copyright notice and this permission notice shall be included | |
" in all copies or substantial portions of the Software. | |
" | |
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | |
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
" }}} | |
"============================================================================= | |
snippet template_plugin | |
if v:version < 700 | |
echoerr "${1:plugin}: Vim 7.0 or later required" | |
finish | |
elseif &cp || exists('g:loaded_$1') | |
finish | |
endif | |
let s:save_cpo = &cpo | |
set cpo&vim | |
"----------------------------------------------------------------------------- | |
" Variables | |
"----------------------------------------------------------------------------- | |
" Commands | |
"----------------------------------------------------------------------------- | |
let &cpo = s:save_cpo | |
unlet s:save_cpo | |
let g:loaded_$1 = 1 | |
" vim: filetype=vim | |
snippet template_ftplugin | |
" `g:template_user_login`'s vimrc suite | |
" Maintainer: `g:template_user_name` <`g:template_user_email`> | |
" FileType Plugin for ${1:FileType} | |
setlocal shiftwidth=2 tabstop=2 expandtab | |
"----------------------------------------------------------------------------- | |
" Keymaps | |
" vim: filetype=vim | |
snippet template_vimrc | |
prev_word '^' | |
" `g:template_user_login`'s vimrc suite | |
" Maintainer: `g:template_user_name` <`g:template_user_email`> | |
${0} | |
" vim: filetype=vim | |
#----------------------------------------------------------------------------- | |
# Unite-outline | |
snippet create_heading | |
prev_word '^' | |
function! s:outline_info.create_heading(which, heading_line, matched_line, context) | |
let heading = { | |
\ 'word' : a:heading_line, | |
\ 'level': 0, | |
\ 'type' : 'generic', | |
\ } | |
if a:which ==# 'heading-1' | |
let heading.type = 'comment' | |
if a:matched_line =~ '^\s' | |
let heading.level = 4 | |
elseif strlen(substitute(a:matched_line, '\s*', '', 'g')) > 40 | |
let heading.level = 1 | |
else | |
let heading.level = 2 | |
endif | |
elseif a:which ==# 'heading' | |
let heading.level = 3 | |
let heading.type = 'function' | |
endif | |
if heading.level > 0 | |
return heading | |
else | |
return {} | |
endif | |
endfunction | |
# vim: filetype=snippet: sw=2: ts=2: expandtab |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment