diff options
| author | Ben Beltran <ben@freshout.us> | 2012-10-08 11:44:10 -0500 |
|---|---|---|
| committer | Ben Beltran <ben@freshout.us> | 2012-10-08 11:44:10 -0500 |
| commit | 0d23b6e515a01a5782532351821ebfa11f3d6cf2 (patch) | |
| tree | aa395b7e50ccb533d6b48b809016ac06f2d5bc8c /vim/ftplugin | |
| parent | a91731eac872b7837c2821341db5888702125cef (diff) | |
Add vim again :)
Diffstat (limited to 'vim/ftplugin')
| -rw-r--r-- | vim/ftplugin/coffee.vim | 233 | ||||
| -rw-r--r-- | vim/ftplugin/cucumber.vim | 132 | ||||
| -rw-r--r-- | vim/ftplugin/git.vim | 36 | ||||
| -rw-r--r-- | vim/ftplugin/gitcommit.vim | 68 | ||||
| -rw-r--r-- | vim/ftplugin/gitconfig.vim | 14 | ||||
| -rw-r--r-- | vim/ftplugin/gitrebase.vim | 42 | ||||
| -rw-r--r-- | vim/ftplugin/gitsendemail.vim | 5 | ||||
| -rw-r--r-- | vim/ftplugin/haml.vim | 67 | ||||
| -rw-r--r-- | vim/ftplugin/html_snip_helper.vim | 10 | ||||
| -rw-r--r-- | vim/ftplugin/markdown.vim | 18 | ||||
| -rw-r--r-- | vim/ftplugin/puppet.vim | 137 | ||||
| -rw-r--r-- | vim/ftplugin/sass.vim | 22 | ||||
| -rw-r--r-- | vim/ftplugin/scss.vim | 12 | ||||
| -rw-r--r-- | vim/ftplugin/textile.vim | 59 |
14 files changed, 855 insertions, 0 deletions
diff --git a/vim/ftplugin/coffee.vim b/vim/ftplugin/coffee.vim new file mode 100644 index 0000000..6af1496 --- /dev/null +++ b/vim/ftplugin/coffee.vim @@ -0,0 +1,233 @@ +" Language: CoffeeScript +" Maintainer: Mick Koch <kchmck@gmail.com> +" URL: http://github.com/kchmck/vim-coffee-script +" License: WTFPL + +if exists("b:did_ftplugin") + finish +endif + +let b:did_ftplugin = 1 + +setlocal formatoptions-=t formatoptions+=croql +setlocal comments=:# +setlocal commentstring=#\ %s + +setlocal errorformat=Error:\ In\ %f\\,\ %m\ on\ line\ %l, + \Error:\ In\ %f\\,\ Parse\ error\ on\ line\ %l:\ %m, + \SyntaxError:\ In\ %f\\,\ %m, + \%-G%.%# + +" Extra options passed to CoffeeMake +if !exists("coffee_make_options") + let coffee_make_options = "" +endif + +" Update `makeprg` for the current filename. This is needed to support filenames +" with spaces and quotes while also supporting generic `make`. +function! s:SetMakePrg() + let &l:makeprg = "coffee -c " . g:coffee_make_options . ' $* ' + \ . fnameescape(expand('%')) +endfunction + +" Set `makeprg` initially. +call s:SetMakePrg() +" Set `makeprg` on rename. +autocmd BufFilePost,BufWritePost,FileWritePost <buffer> call s:SetMakePrg() + +" Reset the global variables used by CoffeeCompile. +function! s:CoffeeCompileResetVars() + " Position in the source buffer + let s:coffee_compile_src_buf = -1 + let s:coffee_compile_src_pos = [] + + " Position in the CoffeeCompile buffer + let s:coffee_compile_buf = -1 + let s:coffee_compile_win = -1 + let s:coffee_compile_pos = [] + + " If CoffeeCompile is watching a buffer + let s:coffee_compile_watch = 0 +endfunction + +" Save the cursor position when moving to and from the CoffeeCompile buffer. +function! s:CoffeeCompileSavePos() + let buf = bufnr('%') + let pos = getpos('.') + + if buf == s:coffee_compile_buf + let s:coffee_compile_pos = pos + else + let s:coffee_compile_src_buf = buf + let s:coffee_compile_src_pos = pos + endif +endfunction + +" Restore the cursor to the source buffer. +function! s:CoffeeCompileRestorePos() + let win = bufwinnr(s:coffee_compile_src_buf) + + if win != -1 + exec win 'wincmd w' + call setpos('.', s:coffee_compile_src_pos) + endif +endfunction + +" Close the CoffeeCompile buffer and clean things up. +function! s:CoffeeCompileClose() + silent! autocmd! CoffeeCompileAuPos + silent! autocmd! CoffeeCompileAuWatch + + call s:CoffeeCompileRestorePos() + call s:CoffeeCompileResetVars() +endfunction + +" Update the CoffeeCompile buffer given some input lines. +function! s:CoffeeCompileUpdate(startline, endline) + let input = join(getline(a:startline, a:endline), "\n") + + " Coffee doesn't like empty input. + if !len(input) + return + endif + + " Compile input. + let output = system('coffee -scb 2>&1', input) + + " Move to the CoffeeCompile buffer. + exec s:coffee_compile_win 'wincmd w' + + " Replace buffer contents with new output and delete the last empty line. + setlocal modifiable + exec '% delete _' + put! =output + exec '$ delete _' + setlocal nomodifiable + + " Highlight as JavaScript if there is no compile error. + if v:shell_error + setlocal filetype= + else + setlocal filetype=javascript + endif + + " Restore the cursor in the compiled output. + call setpos('.', s:coffee_compile_pos) +endfunction + +" Update the CoffeeCompile buffer with the whole source buffer and restore the +" cursor. +function! s:CoffeeCompileWatchUpdate() + call s:CoffeeCompileSavePos() + call s:CoffeeCompileUpdate(1, '$') + call s:CoffeeCompileRestorePos() +endfunction + +" Peek at compiled CoffeeScript in a scratch buffer. We handle ranges like this +" to prevent the cursor from being moved (and its position saved) before the +" function is called. +function! s:CoffeeCompile(startline, endline, args) + " Don't compile the CoffeeCompile buffer. + if bufnr('%') == s:coffee_compile_buf + return + endif + + " Parse arguments. + let watch = a:args =~ '\<watch\>' + let unwatch = a:args =~ '\<unwatch\>' + let vert = a:args =~ '\<vert\%[ical]\>' + let size = str2nr(matchstr(a:args, '\<\d\+\>')) + + " Remove any watch listeners. + silent! autocmd! CoffeeCompileAuWatch + + " If just unwatching, don't compile. + if unwatch + let s:coffee_compile_watch = 0 + return + endif + + if watch + let s:coffee_compile_watch = 1 + endif + + call s:CoffeeCompileSavePos() + + " Build the CoffeeCompile buffer if it doesn't exist. + if s:coffee_compile_buf == -1 + let src_win = bufwinnr(s:coffee_compile_src_buf) + + " Create the new window and resize it. + if vert + let width = size ? size : winwidth(src_win) / 2 + + vertical new + exec 'vertical resize' width + else + " Try to guess the compiled output's height. + let height = size ? size : min([winheight(src_win) / 2, + \ a:endline - a:startline + 2]) + + botright new + exec 'resize' height + endif + + " Set up scratch buffer. + setlocal bufhidden=wipe buftype=nofile + setlocal nobuflisted nomodifiable noswapfile nowrap + + autocmd BufWipeout <buffer> call s:CoffeeCompileClose() + nnoremap <buffer> <silent> q :hide<CR> + + " Save the cursor position on each buffer switch. + augroup CoffeeCompileAuPos + autocmd BufEnter,BufLeave * call s:CoffeeCompileSavePos() + augroup END + + let s:coffee_compile_buf = bufnr('%') + let s:coffee_compile_win = bufwinnr(s:coffee_compile_buf) + endif + + " Go back to the source buffer and do the initial compile. + call s:CoffeeCompileRestorePos() + + if s:coffee_compile_watch + call s:CoffeeCompileWatchUpdate() + + augroup CoffeeCompileAuWatch + autocmd InsertLeave <buffer> call s:CoffeeCompileWatchUpdate() + augroup END + else + call s:CoffeeCompileUpdate(a:startline, a:endline) + endif +endfunction + +" Complete arguments for the CoffeeCompile command. +function! s:CoffeeCompileComplete(arg, cmdline, cursor) + let args = ['unwatch', 'vertical', 'watch'] + + if !len(a:arg) + return args + endif + + let match = '^' . a:arg + + for arg in args + if arg =~ match + return [arg] + endif + endfor +endfunction + +" Don't let new windows overwrite the CoffeeCompile variables. +if !exists("s:coffee_compile_buf") + call s:CoffeeCompileResetVars() +endif + +" Peek at compiled CoffeeScript. +command! -range=% -bar -nargs=* -complete=customlist,s:CoffeeCompileComplete +\ CoffeeCompile call s:CoffeeCompile(<line1>, <line2>, <q-args>) +" Compile the current file. +command! -bang -bar -nargs=* CoffeeMake make<bang> <args> +" Run some CoffeeScript. +command! -range=% -bar CoffeeRun <line1>,<line2>:w !coffee -s diff --git a/vim/ftplugin/cucumber.vim b/vim/ftplugin/cucumber.vim new file mode 100644 index 0000000..ac1d6c9 --- /dev/null +++ b/vim/ftplugin/cucumber.vim @@ -0,0 +1,132 @@ +" Vim filetype plugin +" Language: Cucumber +" Maintainer: Tim Pope <vimNOSPAM@tpope.org> +" Last Change: 2010 Aug 09 + +" Only do this when not done yet for this buffer +if (exists("b:did_ftplugin")) + finish +endif +let b:did_ftplugin = 1 + +setlocal formatoptions-=t formatoptions+=croql +setlocal comments=:# commentstring=#\ %s +setlocal omnifunc=CucumberComplete + +let b:undo_ftplugin = "setl fo< com< cms< ofu<" + +let b:cucumber_root = expand('%:p:h:s?.*[\/]\%(features\|stories\)\zs[\/].*??') + +if !exists("g:no_plugin_maps") && !exists("g:no_cucumber_maps") + nmap <silent><buffer> <C-]> :<C-U>exe <SID>jump('edit',v:count)<CR> + nmap <silent><buffer> <C-W>] :<C-U>exe <SID>jump('split',v:count)<CR> + nmap <silent><buffer> <C-W><C-]> :<C-U>exe <SID>jump('split',v:count)<CR> + nmap <silent><buffer> <C-W>} :<C-U>exe <SID>jump('pedit',v:count)<CR> + let b:undo_ftplugin .= "| sil! nunmap <buffer> <C-]>| sil! nunmap <buffer> <C-W>]| sil! nunmap <buffer> <C-W><C-]>| sil! nunmap <buffer> <C-W>}" +endif + +function! s:jump(command,count) + let steps = s:steps('.') + if len(steps) == 0 || len(steps) < a:count + return 'echoerr "No matching step found"' + elseif len(steps) > 1 && !a:count + return 'echoerr "Multiple matching steps found"' + else + let c = a:count ? a:count-1 : 0 + return a:command.' +'.steps[c][1].' '.escape(steps[c][0],' %#') + endif +endfunction + +function! s:allsteps() + let step_pattern = '\C^\s*\K\k*\>\s*\zs\S.\{-\}\ze\s*\%(do\|{\)\s*\%(|[^|]*|\s*\)\=\%($\|#\)' + let steps = [] + for file in split(glob(b:cucumber_root.'/**/*.rb'),"\n") + let lines = readfile(file) + let num = 0 + for line in lines + let num += 1 + if line =~ step_pattern + let type = matchstr(line,'\w\+') + let steps += [[file,num,type,matchstr(line,step_pattern)]] + endif + endfor + endfor + return steps +endfunction + +function! s:steps(lnum) + let c = indent(a:lnum) + 1 + while synIDattr(synID(a:lnum,c,1),'name') !~# '^$\|Region$' + let c = c + 1 + endwhile + let step = matchstr(getline(a:lnum)[c-1 : -1],'^\s*\zs.\{-\}\ze\s*$') + return filter(s:allsteps(),'s:stepmatch(v:val[3],step)') +endfunction + +function! s:stepmatch(receiver,target) + if a:receiver =~ '^[''"].*[''"]$' + let pattern = '^'.escape(substitute(a:receiver[1:-2],'$\w\+','(.*)','g'),'/').'$' + elseif a:receiver =~ '^/.*/$' + let pattern = a:receiver[1:-2] + elseif a:receiver =~ '^%r..*.$' + let pattern = escape(a:receiver[3:-2],'/') + else + return 0 + endif + try + let vimpattern = substitute(substitute(pattern,'\\\@<!(?:','%(','g'),'\\\@<!\*?','{-}','g') + if a:target =~# '\v'.vimpattern + return 1 + endif + catch + endtry + if has("ruby") && pattern !~ '\\\@<!#{' + ruby VIM.command("return #{if (begin; Kernel.eval('/'+VIM.evaluate('pattern')+'/'); rescue SyntaxError; end) === VIM.evaluate('a:target') then 1 else 0 end}") + else + return 0 + endif +endfunction + +function! s:bsub(target,pattern,replacement) + return substitute(a:target,'\C\\\@<!'.a:pattern,a:replacement,'g') +endfunction + +function! CucumberComplete(findstart,base) abort + let indent = indent('.') + let group = synIDattr(synID(line('.'),indent+1,1),'name') + let type = matchstr(group,'\Ccucumber\zs\%(Given\|When\|Then\)') + let e = matchend(getline('.'),'^\s*\S\+\s') + if type == '' || col('.') < col('$') || e < 0 + return -1 + endif + if a:findstart + return e + endif + let steps = [] + for step in s:allsteps() + if step[2] ==# type + if step[3] =~ '^[''"]' + let steps += [step[3][1:-2]] + elseif step[3] =~ '^/\^.*\$/$' + let pattern = step[3][2:-3] + let pattern = substitute(pattern,'\C^(?:|I )','I ','') + let pattern = s:bsub(pattern,'\\[Sw]','w') + let pattern = s:bsub(pattern,'\\d','1') + let pattern = s:bsub(pattern,'\\[sWD]',' ') + let pattern = s:bsub(pattern,'\[\^\\\="\]','_') + let pattern = s:bsub(pattern,'[[:alnum:]. _-][?*]?\=','') + let pattern = s:bsub(pattern,'\[\([^^]\).\{-\}\]','\1') + let pattern = s:bsub(pattern,'+?\=','') + let pattern = s:bsub(pattern,'(\([[:alnum:]. -]\{-\}\))','\1') + let pattern = s:bsub(pattern,'\\\([[:punct:]]\)','\1') + if pattern !~ '[\\()*?]' + let steps += [pattern] + endif + endif + endif + endfor + call filter(steps,'strpart(v:val,0,strlen(a:base)) ==# a:base') + return sort(steps) +endfunction + +" vim:set sts=2 sw=2: diff --git a/vim/ftplugin/git.vim b/vim/ftplugin/git.vim new file mode 100644 index 0000000..3412251 --- /dev/null +++ b/vim/ftplugin/git.vim @@ -0,0 +1,36 @@ +" Vim filetype plugin +" Language: generic git output +" Maintainer: Tim Pope <vimNOSPAM@tpope.org> + +" Only do this when not done yet for this buffer +if (exists("b:did_ftplugin")) + finish +endif +let b:did_ftplugin = 1 + +if !exists('b:git_dir') + if expand('%:p') =~# '\.git\>' + let b:git_dir = matchstr(expand('%:p'),'.*\.git\>') + elseif $GIT_DIR != '' + let b:git_dir = $GIT_DIR + endif + if (has('win32') || has('win64')) && exists('b:git_dir') + let b:git_dir = substitute(b:git_dir,'\\','/','g') + endif +endif + +if exists('*shellescape') && exists('b:git_dir') && b:git_dir != '' + if b:git_dir =~# '/\.git$' " Not a bare repository + let &l:path = escape(fnamemodify(b:git_dir,':h'),'\, ').','.&l:path + endif + let &l:path = escape(b:git_dir,'\, ').','.&l:path + let &l:keywordprg = 'git --git-dir='.shellescape(b:git_dir).' show' +else + setlocal keywordprg=git\ show +endif +if has('gui_running') + let &l:keywordprg = substitute(&l:keywordprg,'^git\>','git --no-pager','') +endif + +setlocal includeexpr=substitute(v:fname,'^[^/]\\+/','','') +let b:undo_ftplugin = "setl keywordprg< path< includeexpr<" diff --git a/vim/ftplugin/gitcommit.vim b/vim/ftplugin/gitcommit.vim new file mode 100644 index 0000000..16eeb67 --- /dev/null +++ b/vim/ftplugin/gitcommit.vim @@ -0,0 +1,68 @@ +" Vim filetype plugin +" Language: git commit file +" Maintainer: Tim Pope <vimNOSPAM@tpope.org> + +" Only do this when not done yet for this buffer +if (exists("b:did_ftplugin")) + finish +endif + +runtime! ftplugin/git.vim +let b:did_ftplugin = 1 + +set nomodeline + +let b:undo_ftplugin = 'setl modeline<' + +if &textwidth == 0 + " make sure that log messages play nice with git-log on standard terminals + setlocal textwidth=72 + let b:undo_ftplugin .= "|setl tw<" +endif + +if exists("g:no_gitcommit_commands") || v:version < 700 + finish +endif + +if !exists("b:git_dir") + let b:git_dir = expand("%:p:h") +endif + +" Automatically diffing can be done with: +" autocmd BufRead *.git/COMMIT_EDITMSG DiffGitCached | wincmd p +command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0,b:git_dir,<f-args>) + +function! s:diffcomplete(A,L,P) + let args = "" + if a:P <= match(a:L." -- "," -- ")+3 + let args = args . "-p\n--stat\n--shortstat\n--summary\n--patch-with-stat\n--no-renames\n-B\n-M\n-C\n" + end + if exists("b:git_dir") && a:A !~ '^-' + let tree = fnamemodify(b:git_dir,':h') + if strpart(getcwd(),0,strlen(tree)) == tree + let args = args."\n".system("git diff --cached --name-only") + endif + endif + return args +endfunction + +function! s:gitdiffcached(bang,gitdir,...) + let tree = fnamemodify(a:gitdir,':h') + let name = tempname() + let git = "git" + if strpart(getcwd(),0,strlen(tree)) != tree + let git .= " --git-dir=".(exists("*shellescape") ? shellescape(a:gitdir) : '"'.a:gitdir.'"') + endif + if a:0 + let extra = join(map(copy(a:000),exists("*shellescape") ? 'shellescape(v:val)' : "'\"'.v:val.'\"'")) + else + let extra = "-p --stat=".&columns + endif + call system(git." diff --cached --no-color ".extra." > ".(exists("*shellescape") ? shellescape(name) : name)) + exe "pedit ".(exists("*fnameescape") ? fnameescape(name) : name) + wincmd P + let b:git_dir = a:gitdir + command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0,b:git_dir,<f-args>) + nnoremap <silent> q :q<CR> + setlocal buftype=nowrite nobuflisted noswapfile nomodifiable filetype=git +endfunction diff --git a/vim/ftplugin/gitconfig.vim b/vim/ftplugin/gitconfig.vim new file mode 100644 index 0000000..2869fc9 --- /dev/null +++ b/vim/ftplugin/gitconfig.vim @@ -0,0 +1,14 @@ +" Vim filetype plugin +" Language: git config file +" Maintainer: Tim Pope <vimNOSPAM@tpope.org> + +" Only do this when not done yet for this buffer +if (exists("b:did_ftplugin")) + finish +endif +let b:did_ftplugin = 1 + +setlocal formatoptions-=t formatoptions+=croql +setlocal comments=:#,:; commentstring=;\ %s + +let b:undo_ftplugin = "setl fo< com< cms<" diff --git a/vim/ftplugin/gitrebase.vim b/vim/ftplugin/gitrebase.vim new file mode 100644 index 0000000..5d111dd --- /dev/null +++ b/vim/ftplugin/gitrebase.vim @@ -0,0 +1,42 @@ +" Vim filetype plugin +" Language: git rebase --interactive +" Maintainer: Tim Pope <vimNOSPAM@tpope.org> + +" Only do this when not done yet for this buffer +if (exists("b:did_ftplugin")) + finish +endif + +runtime! ftplugin/git.vim +let b:did_ftplugin = 1 + +setlocal comments=:# commentstring=#\ %s formatoptions-=t +if !exists("b:undo_ftplugin") + let b:undo_ftplugin = "" +endif +let b:undo_ftplugin = b:undo_ftplugin."|setl com< cms< fo<" + +function! s:choose(word) + s/^\(\w\+\>\)\=\(\s*\)\ze\x\{4,40\}\>/\=(strlen(submatch(1)) == 1 ? a:word[0] : a:word) . substitute(submatch(2),'^$',' ','')/e +endfunction + +function! s:cycle() + call s:choose(get({'s':'edit','p':'squash','e':'reword','r':'fixup'},getline('.')[0],'pick')) +endfunction + +command! -buffer -bar Pick :call s:choose('pick') +command! -buffer -bar Squash :call s:choose('squash') +command! -buffer -bar Edit :call s:choose('edit') +command! -buffer -bar Reword :call s:choose('reword') +command! -buffer -bar Fixup :call s:choose('fixup') +command! -buffer -bar Cycle :call s:cycle() +" The above are more useful when they are mapped; for example: +"nnoremap <buffer> <silent> S :Cycle<CR> + +if exists("g:no_plugin_maps") || exists("g:no_gitrebase_maps") + finish +endif + +nnoremap <buffer> <expr> K col('.') < 7 && expand('<Lt>cword>') =~ '\X' && getline('.') =~ '^\w\+\s\+\x\+\>' ? 'wK' : 'K' + +let b:undo_ftplugin = b:undo_ftplugin . "|nunmap <buffer> K" diff --git a/vim/ftplugin/gitsendemail.vim b/vim/ftplugin/gitsendemail.vim new file mode 100644 index 0000000..d97cbda --- /dev/null +++ b/vim/ftplugin/gitsendemail.vim @@ -0,0 +1,5 @@ +" Vim filetype plugin +" Language: git send-email message +" Maintainer: Tim Pope <vimNOSPAM@tpope.org> + +runtime! ftplugin/mail.vim diff --git a/vim/ftplugin/haml.vim b/vim/ftplugin/haml.vim new file mode 100644 index 0000000..df818f4 --- /dev/null +++ b/vim/ftplugin/haml.vim @@ -0,0 +1,67 @@ +" Vim filetype plugin +" Language: Haml +" Maintainer: Tim Pope <vimNOSPAM@tpope.org> +" Last Change: 2010 May 21 + +" Only do this when not done yet for this buffer +if exists("b:did_ftplugin") + finish +endif + +let s:save_cpo = &cpo +set cpo-=C + +" Define some defaults in case the included ftplugins don't set them. +let s:undo_ftplugin = "" +let s:browsefilter = "All Files (*.*)\t*.*\n" +let s:match_words = "" + +runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim +unlet! b:did_ftplugin + +" Override our defaults if these were set by an included ftplugin. +if exists("b:undo_ftplugin") + let s:undo_ftplugin = b:undo_ftplugin + unlet b:undo_ftplugin +endif +if exists("b:browsefilter") + let s:browsefilter = b:browsefilter + unlet b:browsefilter +endif +if exists("b:match_words") + let s:match_words = b:match_words + unlet b:match_words +endif + +runtime! ftplugin/ruby.vim ftplugin/ruby_*.vim ftplugin/ruby/*.vim +let b:did_ftplugin = 1 + +" Combine the new set of values with those previously included. +if exists("b:undo_ftplugin") + let s:undo_ftplugin = b:undo_ftplugin . " | " . s:undo_ftplugin +endif +if exists ("b:browsefilter") + let s:browsefilter = substitute(b:browsefilter,'\cAll Files (\*\.\*)\t\*\.\*\n','','') . s:browsefilter +endif +if exists("b:match_words") + let s:match_words = b:match_words . ',' . s:match_words +endif + +" Change the browse dialog on Win32 to show mainly Haml-related files +if has("gui_win32") + let b:browsefilter="Haml Files (*.haml)\t*.haml\nSass Files (*.sass)\t*.sass\n" . s:browsefilter +endif + +" Load the combined list of match_words for matchit.vim +if exists("loaded_matchit") + let b:match_words = s:match_words +endif + +setlocal comments= commentstring=-#\ %s + +let b:undo_ftplugin = "setl cms< com< " + \ " | unlet! b:browsefilter b:match_words | " . s:undo_ftplugin + +let &cpo = s:save_cpo + +" vim:set sw=2: diff --git a/vim/ftplugin/html_snip_helper.vim b/vim/ftplugin/html_snip_helper.vim new file mode 100644 index 0000000..2e54570 --- /dev/null +++ b/vim/ftplugin/html_snip_helper.vim @@ -0,0 +1,10 @@ +" Helper function for (x)html snippets +if exists('s:did_snip_helper') || &cp || !exists('loaded_snips') + finish +endif +let s:did_snip_helper = 1 + +" Automatically closes tag if in xhtml +fun! Close() + return stridx(&ft, 'xhtml') == -1 ? '' : ' /' +endf diff --git a/vim/ftplugin/markdown.vim b/vim/ftplugin/markdown.vim new file mode 100644 index 0000000..28cac11 --- /dev/null +++ b/vim/ftplugin/markdown.vim @@ -0,0 +1,18 @@ +" Vim filetype plugin +" Language: Markdown +" Maintainer: Tim Pope <vimNOSPAM@tpope.org> + +if exists("b:did_ftplugin") + finish +endif + +runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim +unlet! b:did_ftplugin + +setlocal comments=fb:*,fb:-,fb:+,n:> commentstring=>\ %s +setlocal formatoptions+=tcqln +setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^[-*+]\\s\\+ + +let b:undo_ftplugin .= "|setl cms< com< fo<" + +" vim:set sw=2: diff --git a/vim/ftplugin/puppet.vim b/vim/ftplugin/puppet.vim new file mode 100644 index 0000000..1b00868 --- /dev/null +++ b/vim/ftplugin/puppet.vim @@ -0,0 +1,137 @@ +" Vim filetype plugin +" Language: Puppet +" Maintainer: Todd Zullinger <tmz@pobox.com> +" Last Change: 2009 Aug 19 +" vim: set sw=4 sts=4: + +if exists("b:did_ftplugin") + finish +endif +let b:did_ftplugin = 1 + +if !exists("no_plugin_maps") && !exists("no_puppet_maps") + if !hasmapto("<Plug>AlignRange") + map <buffer> <LocalLeader>= <Plug>AlignRange + endif +endif + +noremap <buffer> <unique> <script> <Plug>AlignArrows :call <SID>AlignArrows()<CR> +noremap <buffer> <unique> <script> <Plug>AlignRange :call <SID>AlignRange()<CR> + +iabbrev => =><C-R>=<SID>AlignArrows('=>')<CR> +iabbrev +> +><C-R>=<SID>AlignArrows('+>')<CR> + +if exists('*s:AlignArrows') + finish +endif + +let s:arrow_re = '[=+]>' +let s:selector_re = '[=+]>\s*\$.*\s*?\s*{\s*$' + +" set keywordprg to 'pi' (alias for puppet describe) +" this lets K invoke pi for word under cursor +setlocal keywordprg=puppet\ describe + +function! s:AlignArrows(op) + let cursor_pos = getpos('.') + let lnum = line('.') + let line = getline(lnum) + if line !~ s:arrow_re + return + endif + let pos = stridx(line, a:op) + let start = lnum + let end = lnum + let pnum = lnum - 1 + while 1 + let pline = getline(pnum) + if pline !~ s:arrow_re || pline =~ s:selector_re + break + endif + let start = pnum + let pnum -= 1 + endwhile + let cnum = end + while 1 + let cline = getline(cnum) + if cline !~ s:arrow_re || + \ (indent(cnum) != indent(cnum+1) && getline(cnum+1) !~ '\s*}') + break + endif + let end = cnum + let cnum += 1 + endwhile + call s:AlignSection(start, end) + let cursor_pos[2] = stridx(getline('.'), a:op) + strlen(a:op) + 1 + call setpos('.', cursor_pos) + return '' +endfunction + +function! s:AlignRange() range + call s:AlignSection(a:firstline, a:lastline) +endfunction + +" AlignSection and AlignLine are from the vim wiki: +" http://vim.wikia.com/wiki/Regex-based_text_alignment +function! s:AlignSection(start, end) + let extra = 1 + let sep = s:arrow_re + let maxpos = 0 + let section = getline(a:start, a:end) + for line in section + let pos = match(line, ' *'.sep) + if maxpos < pos + let maxpos = pos + endif + endfor + call map(section, 's:AlignLine(v:val, sep, maxpos, extra)') + call setline(a:start, section) +endfunction + +function! s:AlignLine(line, sep, maxpos, extra) + let m = matchlist(a:line, '\(.\{-}\) \{-}\('.a:sep.'.*\)') + if empty(m) + return a:line + endif + let spaces = repeat(' ', a:maxpos - strlen(m[1]) + a:extra) + return m[1] . spaces . m[2] +endfunction + +" detect if we are in a module and set variables for classpath (autoloader), +" modulename, modulepath, and classname +" useful to use in templates +function! s:SetModuleVars() + + " set these to any dirs you want to stop searching on + " useful to stop vim from spinning disk looking all over for init.pp + " probably only a macosx problem with /tmp since it's really /private/tmp + " but it's here if you find vim spinning on new files in certain places + if !exists("g:puppet_stop_dirs") + let g:puppet_stop_dirs = '/tmp;/private/tmp' + endif + + " search path for init.pp + let b:search_path = './**' + let b:search_path = b:search_path . ';' . getcwd() . ';' . g:puppet_stop_dirs + + " find what we assume to be our module dir + let b:initpp = findfile("init.pp", b:search_path) " find an init.pp up or down + let b:module_path = fnamemodify(b:initpp, ":p:h:h") " full path to module name + let b:module_name = fnamemodify(b:module_path, ":t") " just the module name + + " sub out the full path to the module with the name and replace slashes with :: + let b:classpath = fnamemodify(expand("%:p:r"), ':s#' . b:module_path . '/manifests#' . b:module_name . '#'. ":gs?/?::?") + let b:classname = expand("%:t:r") + + " if we don't start with a word we didn't replace the module_path + " probably b/c we couldn't find an init.pp / not a module + " so we assume that root of the filename is the class (sane for throwaway + " manifests + if b:classpath =~ '^::' + let b:classpath = b:classname + endif +endfunction + +if exists("g:puppet_module_detect") + call s:SetModuleVars() +endif diff --git a/vim/ftplugin/sass.vim b/vim/ftplugin/sass.vim new file mode 100644 index 0000000..64232a0 --- /dev/null +++ b/vim/ftplugin/sass.vim @@ -0,0 +1,22 @@ +" Vim filetype plugin +" Language: Sass +" Maintainer: Tim Pope <vimNOSPAM@tpope.org> +" Last Change: 2010 Jul 26 + +" Only do this when not done yet for this buffer +if exists("b:did_ftplugin") + finish +endif +let b:did_ftplugin = 1 + +let b:undo_ftplugin = "setl cms< def< inc< inex< ofu< sua<" + +setlocal commentstring=//\ %s +setlocal define=^\\s*\\%(@mixin\\\|=\\) +setlocal includeexpr=substitute(v:fname,'\\%(.*/\\\|^\\)\\zs','_','') +setlocal omnifunc=csscomplete#CompleteCSS +setlocal suffixesadd=.sass,.scss,.css + +let &l:include = '^\s*@import\s\+\%(url(\)\=["'']\=' + +" vim:set sw=2: diff --git a/vim/ftplugin/scss.vim b/vim/ftplugin/scss.vim new file mode 100644 index 0000000..981fb1b --- /dev/null +++ b/vim/ftplugin/scss.vim @@ -0,0 +1,12 @@ +" Vim filetype plugin +" Language: SCSS +" Maintainer: Tim Pope <vimNOSPAM@tpope.org> +" Last Change: 2010 Jul 26 + +if exists("b:did_ftplugin") + finish +endif + +runtime! ftplugin/sass.vim + +" vim:set sw=2: diff --git a/vim/ftplugin/textile.vim b/vim/ftplugin/textile.vim new file mode 100644 index 0000000..fa84c49 --- /dev/null +++ b/vim/ftplugin/textile.vim @@ -0,0 +1,59 @@ +" textile.vim +" +" Tim Harper (tim.theenchanter.com) + +command! -nargs=0 TextileRenderFile call TextileRenderBufferToFile() +command! -nargs=0 TextileRenderTab call TextileRenderBufferToTab() +command! -nargs=0 TextilePreview call TextileRenderBufferToPreview() +noremap <buffer> <Leader>rp :TextilePreview<CR> +noremap <buffer> <Leader>rf :TextileRenderFile<CR> +noremap <buffer> <Leader>rt :TextileRenderTab<CR> +setlocal ignorecase +setlocal wrap +setlocal lbr + +function! TextileRender(lines) + if (system('which ruby') == "") + throw "Could not find ruby!" + end + + let text = join(a:lines, "\n") + let html = system("ruby -e \"def e(msg); puts msg; exit 1; end; begin; require 'rubygems'; rescue LoadError; e('rubygems not found'); end; begin; require 'redcloth'; rescue LoadError; e('RedCloth gem not installed. Run this from the terminal: sudo gem install RedCloth'); end; puts(RedCloth.new(\\$stdin.read).to_html(:textile))\"", text) + return html +endfunction + +function! TextileRenderFile(lines, filename) + let html = TextileRender(getbufline(bufname("%"), 1, '$')) + let html = "<html><head><title>" . bufname("%") . "</title><body>\n" . html . "\n</body></html>" + return writefile(split(html, "\n"), a:filename) +endfunction + +function! TextileRenderBufferToPreview() + let filename = "/tmp/textile-preview.html" + call TextileRenderFile(getbufline(bufname("%"), 1, '$'), filename) + " Verify if browser was set + if !exists("g:TextileBrowser") + let g:TextileBrowser='Safari' + endif + " call configured browser according OS + if !exists("g:TextileOS") || g:TextileOS == 'mac' + call system("open -a \"".g:TextileBrowser."\" ".filename) + else + echo g:TextileBrowser." ".filename + call system(g:TextileBrowser." ".filename) + endif +endfunction + +function! TextileRenderBufferToFile() + let filename = input("Filename:", substitute(bufname("%"), "textile$", "html", ""), "file") + call TextileRenderFile(getbufline(bufname("%"), 1, '$'), filename) + echo "Rendered to '" . filename . "'" +endfunction + +function! TextileRenderBufferToTab() + let html = TextileRender(getbufline(bufname("%"), 1, '$')) + tabnew + call append("^", split(html, "\n")) + set syntax=html +endfunction + |