Skip to content

Instantly share code, notes, and snippets.

@eraserhd
Created December 14, 2011 03:32
Show Gist options
  • Save eraserhd/1475153 to your computer and use it in GitHub Desktop.
Save eraserhd/1475153 to your computer and use it in GitHub Desktop.
Sample project.vim
map <leader>xt :call RunKiwiSpecs()<CR>
map <leader>xb :call Build()<CR>
augroup cprog
au!
autocmd BufNewFile,BufRead * set formatoptions=tcql nocindent comments&
autocmd BufNewFile,BufRead *.c,*.cc,*.cpp,*.hh,*.hpp,*.h set formatoptions=croql cindent comments=sr:/*,mb:*,el:*/,:// sts=4 sw=4 et
augroup END
augroup objc
au!
autocmd BufNewFile,BufRead *.m,*.mm set filetype=objc cindent sts=4 ts=8 sw=4 et
autocmd BufNewFile,BufRead *.m,*.mm set foldmethod=marker
augroup END
func! RunKiwiSpecs()
call RunBuildCommand("xcodebuild -target VimxCodeSpecs -arch x86_64 -configuration Debug")
endfunc
func! Build()
call RunBuildCommand("xcodebuild -target VimxCode -arch x86_64 -configuration Debug")
endfunc
func! RunBuildCommand(cmd)
echo "Building... "
exec "silent !" . a:cmd . " >build/vim.log 2>&1"
" xcodebuild does NOT set exit code properly, so check the build log
silent !grep -q '^\*\* BUILD FAILED' build/vim.log
redraw!
if !v:shell_error
set errorformat=
\%f:%l:%c:{%*[^}]}:\ error:\ %m,
\%f:%l:%c:{%*[^}]}:\ fatal\ error:\ %m,
\%f:%l:%c:{%*[^}]}:\ warning:\ %m,
\%f:%l:%c:\ error:\ %m,
\%f:%l:%c:\ fatal\ error:\ %m,
\%f:%l:%c:\ warning:\ %m,
\%f:%l:\ error:\ %m,
\%f:%l:\ fatal\ error:\ %m,
\%f:%l:\ warning:\ %m
cfile! build/vim.log
else
echo "Building... OK"
endif
endfunc
com! -nargs=1 -complete=customlist,CompleteClass Class :call Class(<q-args>)
func! Class(name)
if filereadable("VimxCode/" . a:name . "Spec.mm")
exec "tabedit VimxCode/" . a:name . "Spec.mm"
exec "vsplit VimxCode/" . a:name . ".mm"
exec "split VimxCode/" . a:name . ".h"
else
exec "tabedit VimxCode/" . a:name . ".mm"
if filereadable("VimxCode/" . a:name . ".h")
exec "split VimxCode/" . a:name . ".h"
endif
endif
endfunc
func! CompleteClass(ArgLead, CmdLine, CursorPos)
let l = split(glob("VimxCode/*.mm"))
let l = map(l, 'substitute(v:val, "^VimxCode/", "", "")')
let l = map(l, 'substitute(v:val, "\.mm$", "", "")')
let l = filter(l, 'v:val !~ "Spec$"')
let l = filter(l, 'v:val =~ "^' . escape(a:ArgLead, "'\"\\") . '"')
return l
endfunc
" vi:set sts=2 sw=2 ai et:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment