diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1377554 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.swp diff --git a/vim/cf5-compiler.vim b/vim/cf5-compiler.vim index 99f4bea..652eb08 100755 --- a/vim/cf5-compiler.vim +++ b/vim/cf5-compiler.vim @@ -1,6 +1,10 @@ -" +" {{{1 " Functions to compile and link a single c/cpp file. " +" let g:cf5output +" =0 - no output window opened. +" =1 - ouput window opened. +" "if exists("g:loaded_vahagn_compiler") | finish | endif let g:loaded_vahagn_compiler = 1 @@ -12,12 +16,9 @@ if !exists('*FirstModeLine') endif " -" Windows +" Windows {{{1 " -let g:argv="" -let g:cppflags="" -let g:wcppflags="/O2 /EHsc /DWIN32" -function! s:CompileMSVC() +function! s:CompileMSVC() "{{{2 let exename=expand("%:p:r:s,$,.exe,") let srcname=expand("%") " compile it @@ -36,7 +37,7 @@ function! s:CompileMSVC() echo eout endfunction -function! s:CompileJava() +function! s:CompileJava() "{{{2 " compile it let cmd = "javac " . g:javaflags . " " . expand("%") echo cmd @@ -54,7 +55,7 @@ function! s:CompileJava() echo eout endfunction -function! s:CompileWindows() +function! s:CompileWindows() "{{{2 let ext=expand("%:e") if ext=="java" call s:CompileJava() @@ -64,43 +65,109 @@ function! s:CompileWindows() endif endfunction +" +" Linux {{{1 " -" Linux -" -let g:lcppflags="-O2" -function! s:CompileGCC() +function! s:CompileGCC() "{{{2 let exename=expand("%:p:r:s,$,.exe,") let srcname=expand("%") " compile it let ccline="g++ ".g:cppflags." ".g:lcppflags." ".srcname." -o".exename - echo ccline + call s:appendOutput(ccline) let cout = system( ccline ) if v:shell_error - echo cout + call s:appendOutput(cout) return endif - echo cout + call s:appendOutput(cout) " run it - let cmdline="LD_LIBRARY_PATH=".g:ldlibrarypath.":".$LD_LIBRARY_PATH." ".exename - echo cmdline + let cmdline="LD_LIBRARY_PATH=".g:ldlibpath.":".$LD_LIBRARY_PATH." ".exename." ".g:argv + call s:appendOutput(cmdline) let eout = system( cmdline ) - echo eout + call s:appendOutput(eout) endfunction -function! s:CompileLinux() +function! s:CompileLinux() "{{{2 call s:CompileGCC() endfunction " -" Load compile instructions and call window or linux compiler. +" Output Window {{{1 +" +" Create output window. {{{2 +" +function! s:getOutputWindow() + if !exists("w:outputwin") + let w:outputwin=tempname().'_output' + endif + let obuff = w:outputwin + + let winnr = bufwinnr('^'.obuff.'$') + + if (winnr < 0) + execute "below 10new ".obuff + setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap + " setlocal nomodifiable + let winnr = bufwinnr('^'.obuff.'$') + endif + + return winnr +endfunction +" +" Append text to output window. {{{2 +" +function! s:appendOutput( text ) + if exists("g:cf5output") && (g:cf5output==1) + let cwinnr = winnr() + let owinnr = s:getOutputWindow() +" setlocal modifiable + execute owinnr . 'wincmd w' + execute 'normal! Go'.a:text +" setlocal nomodifiable + execute cwinnr.'wincmd w' + else + echo a:text + endif +endfunction +" +" Clear text from output window. {{{2 +" +function! s:clearOutputWindow() + if exists("g:cf5output") && (g:cf5output==1) + let cwinnr = winnr() + let owinnr = s:getOutputWindow() +" setlocal modifiable + execute owinnr . 'wincmd w' + execute 'normal ggdG' +" setlocal nomodifiable + execute cwinnr . 'wincmd w' + endif +endfunction +" +" Init global variables with default values. {{{1 +" +function! s:initDefaults() + let g:cf5output=0 + let g:argv="" + let g:cppflags="" + let g:wcppflags="/O2 /EHsc /DWIN32" + let g:lcppflags="-O2" + let g:ldlibpath="" +endfunction +" +" Load compile instructions and call window or linux compiler. {{{1 " function! CF5Compile() + " + " First init global variables to let cf5-opt override it. + " + call s:initDefaults() " " Source compile-opt.vim if exists. " - let copt=expand("%:p:h")."/compile-opt.vim" - if filereadable(copt) - source copt + verbose let l:copt=expand("%:p:h")."/cf5-opt.vim" + if filereadable(l:copt) + exec ":source ".l:copt endif " " Set source specific compiler options. @@ -110,6 +177,10 @@ function! CF5Compile() " execute g:cf5script "endif " + " Clear output window + " + call s:clearOutputWindow() + " " Compile. " if has("win32") || has("win64") @@ -119,5 +190,3 @@ function! CF5Compile() endif endfunction - - diff --git a/vim/vimrc b/vim/vimrc index 3cc5ad1..11f2001 100755 --- a/vim/vimrc +++ b/vim/vimrc @@ -73,7 +73,27 @@ if exists('&modeline') set modeline set modelines=10 endif - +" +" Set fold method if supported +" +if has('folding') + set nofoldenable + set foldmethod=indent "fold based on indent + set foldnestmax=5 + set foldlevel=1 + if has("autocmd") + autocmd FileType vim setlocal foldmethod=marker + autocmd FileType c setlocal foldmethod=syntax + autocmd FileType h setlocal foldmethod=syntax + autocmd FileType cpp setlocal foldmethod=syntax + endif +endif +" +" P4 +" +command! -nargs=* PFedit :!p4 edit % +command! -nargs=* PFrevert :!p4 revert % +command! -nargs=* PFdiff :!p4 diff % " Only do this part when compiled with support for autocommands. if has("autocmd") @@ -194,6 +214,8 @@ if has("gui_running") \set showtabline=1 \endif - " Open fine in a new tab. + " Open file in a new tab. map :browse tabnew %:p:h + endif +