From 0d23b6e515a01a5782532351821ebfa11f3d6cf2 Mon Sep 17 00:00:00 2001 From: Ben Beltran Date: Mon, 8 Oct 2012 11:44:10 -0500 Subject: Add vim again :) --- vim/ftplugin/coffee.vim | 233 ++++++++++++++++++++++++++++++++++++++ vim/ftplugin/cucumber.vim | 132 +++++++++++++++++++++ vim/ftplugin/git.vim | 36 ++++++ vim/ftplugin/gitcommit.vim | 68 +++++++++++ vim/ftplugin/gitconfig.vim | 14 +++ vim/ftplugin/gitrebase.vim | 42 +++++++ vim/ftplugin/gitsendemail.vim | 5 + vim/ftplugin/haml.vim | 67 +++++++++++ vim/ftplugin/html_snip_helper.vim | 10 ++ vim/ftplugin/markdown.vim | 18 +++ vim/ftplugin/puppet.vim | 137 ++++++++++++++++++++++ vim/ftplugin/sass.vim | 22 ++++ vim/ftplugin/scss.vim | 12 ++ vim/ftplugin/textile.vim | 59 ++++++++++ 14 files changed, 855 insertions(+) create mode 100644 vim/ftplugin/coffee.vim create mode 100644 vim/ftplugin/cucumber.vim create mode 100644 vim/ftplugin/git.vim create mode 100644 vim/ftplugin/gitcommit.vim create mode 100644 vim/ftplugin/gitconfig.vim create mode 100644 vim/ftplugin/gitrebase.vim create mode 100644 vim/ftplugin/gitsendemail.vim create mode 100644 vim/ftplugin/haml.vim create mode 100644 vim/ftplugin/html_snip_helper.vim create mode 100644 vim/ftplugin/markdown.vim create mode 100644 vim/ftplugin/puppet.vim create mode 100644 vim/ftplugin/sass.vim create mode 100644 vim/ftplugin/scss.vim create mode 100644 vim/ftplugin/textile.vim (limited to 'vim/ftplugin') 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 +" 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 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 =~ '\' + let unwatch = a:args =~ '\' + let vert = a:args =~ '\' + 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 call s:CoffeeCompileClose() + nnoremap q :hide + + " 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 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(, , ) +" Compile the current file. +command! -bang -bar -nargs=* CoffeeMake make +" Run some CoffeeScript. +command! -range=% -bar CoffeeRun ,: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 +" 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 :exe jump('edit',v:count) + nmap ] :exe jump('split',v:count) + nmap :exe jump('split',v:count) + nmap } :exe jump('pedit',v:count) + let b:undo_ftplugin .= "| sil! nunmap | sil! nunmap ]| sil! nunmap | sil! nunmap }" +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,'\\\@ + +" 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 + +" 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(0,b:git_dir,) + +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(0,b:git_dir,) + nnoremap q :q + 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 + +" 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 + +" 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 S :Cycle + +if exists("g:no_plugin_maps") || exists("g:no_gitrebase_maps") + finish +endif + +nnoremap K col('.') < 7 && expand('cword>') =~ '\X' && getline('.') =~ '^\w\+\s\+\x\+\>' ? 'wK' : 'K' + +let b:undo_ftplugin = b:undo_ftplugin . "|nunmap 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 + +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 +" 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 + +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 +" 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("AlignRange") + map = AlignRange + endif +endif + +noremap