From be971a79fae43b2a21661413fcf9ab28e36d55be Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Wed, 16 Jan 2013 21:07:53 -0800 Subject: [PATCH] project.vim stuff --- vimrc | 60 +++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/vimrc b/vimrc index 4fef1b7..715ebc0 100644 --- a/vimrc +++ b/vimrc @@ -167,40 +167,54 @@ function! strip_trailing_whitespace() call cursor(l, c) endfunction - -function! find_project_file() +function! FindProjectFileOrDirectory(fod) let l:dir = getcwd() - " Search up the path, starting at the current working directory, for a - " project.vim file and return the path to it, if it exists. - while l:dir != '/' - let l:project_file = l:dir . '/project.vim' - if filereadable(l:project_file) - return l:project_file + " Search up the path, starting at the current working directory, for the + " file or directory given in a:fod and return the path to it, if it exists. + while l:dir != "/" + let l:file_or_dir = l:dir . "/" . a:fod + if filereadable(l:file_or_dir) || isdirectory(l:file_or_dir) + return l:file_or_dir endif let l:dir = fnamemodify(l:dir, ':h') endwhile - return '' + return "" endfunction +function! GetProjectRuntimeDirectory() + return FindProjectFileOrDirectory("vim") +endfunction -function! source_project_file() - let l:project_file = find_project_file() - if l:project_file != '' - exec 'source ' . l:project_file +function! GetProjectFile() + return FindProjectFileOrDirectory("project.vim") +endfunction + +function! SourceProjectFile() + let l:project_file = GetProjectFile() + if l:project_file != "" + exec "source " . l:project_file + endif +endfunction + +function! AddProjectRuntimeDirectory() + let l:project_rtp = GetProjectRuntimeDirectory() + if isdirectory(l:project_rtp) + exec "set rtp+=" . l:project_rtp endif endfunction let mapleader=',' + " strip all trailing whitespace in the current file nnoremap W :call strip_trailing_whitespace() -" (Re)load a project.vim file -nnoremap P :exec 'edit ' . source_project_file() -" edit and source .vimrc and project.vim files -nmap ev :e $MYVIMRC -nmap sv :source $MYVIMRC -nmap eP :e find_project_file() +" Source .vimrc and project.vim files +nmap V :source $MYVIMRC +nmap P :call SourceProjectFile() +" Edit my .vimrc and project.vim files +nmap eV :edit $MYVIMRC +nmap eP :exec 'edit ' . GetProjectFile() " hide search terms nmap :setlocal invhlsearch @@ -245,13 +259,15 @@ if has('autocmd') " All my projects are in the ~/Code directory. Look for and source a " project.vim file if one exists. autocmd VimEnter ~/Code/* - \ call source_project_file() + \ call SourceProjectFile() + autocmd VimEnter ~/Code/* + \ call AddProjectRuntimeDirectory() " Reload snippets after editing the snippets file. Snippet files are " .snippets. Get from the filename and reload the " snippets for that type. - autocmd BufWritePost *.snippets - \ :call ReloadSnippets(expand('%:t:r')) + "autocmd BufWritePost *.snippets + " \ :call ReloadSnippets(expand('%:t:r')) " Clean whitespace before saving: Python, C, HTML, and Objective-C autocmd BufWritePre *.py,*.h,*.c,*.html,*.m,*.mm,*.cc,*.hh