" =========================================================================== " File: basics.vim " Author: Stefan Liebl (S.Liebl@gmx.de) " Description: some usefull standard functions " " Must be first file in this directory " =========================================================================== if (v:version < 700) echo 'update your vim' endif " ---------------- " useful functions " ---------------- function GetLine() let line_nr = line('.') let line = getline(line_nr) return line endfunction function PrintLine(text) let line_nr = line('.') let line = GetLine() echo a:text . line_nr . ' ' . line endfunction function ListToRegexp(list) let groups = [] for item in a:list let r = escape(item, '/*.') call add(groups, '\('.r.'\)') endfor let re = join(groups, '\|') return re endfunction command -nargs=1 EchoDebug call EchoDebug() function EchoDebug(text) if exists('g:debug') if (g:debug > 0) execute 'echo "' . a:text . '"' endif endif endfunction " Go back in jumplist to an older file function! GotoLastFile() let actfilename = expand('%') let filename = actfilename while filename == actfilename execute "normal \" let filename = expand('%') endwhile endfunction " inputdialog whitch updates Variable and returns result function VariableUpdateDialog(prompt, varName, ...) execute 'let l:var=' . a:varName if a:0 > 0 let l:var = inputdialog(a:prompt, l:var, a:1) else let l:var = inputdialog(a:prompt, l:var) endif execute 'let ' . a:varName . '= l:var' return l:var endfunction "command -nargs=1 PathNormpath call PathNormpath('') "function PathNormpath(string) " if has('python') " try "python <\)', '\1\2', '') "echo 'result:'.result.':'. a:bits digits endif return result endfunction " get date function GetDate() let l:full_date = system('date /T') let l:day = matchstr(l:full_date,'\a\+') let l:date = matchstr(l:full_date,'[0-9.]\+') return l:date endfunction "function Wait(seconds) " let starttime = localtime() " while ((localtime() - starttime) < a:seconds) " endwhile "endfunction function ReversePatch() silent execute '!patch -R -o' v:fname_out v:fname_in '<' v:fname_diff endfunction EchoDebug 'loaded _stefan.vim'