diff --git a/vimrc b/vimrc index 5fe53f5..1d07cf4 100644 --- a/vimrc +++ b/vimrc @@ -435,9 +435,10 @@ augroup campoCmds autocmd BufWritePost .vimrc silent! source $MYVIMRC autocmd BufWritePost *.vim silent! source $MYVIMRC autocmd BufWritePost ~/.vimrc.private silent! source $MYVIMRC + autocmd BufWritePost ~/.vimrc_templates.private silent! source $MYVIMRC " Remove trailing whitespace when saving any file. - function! s:StripTrailingWhitespaces() + function! StripTrailingWhitespaces() if g:campo_strip_trailing_whitespace == 1 if len(g:campo_directories_to_ignore_when_stripping_trailing_whitespace) for path in g:campo_directories_to_ignore_when_stripping_trailing_whitespace @@ -484,127 +485,8 @@ augroup campoCmds %s/\s\+$//e call cursor(l, c) endfun - autocmd BufWritePre * call s:StripTrailingWhitespaces() + autocmd BufWritePre * call StripTrailingWhitespaces() - "//////////////////////////////////////////////////////////////// - " FILE TEMPLATES - "//////////////////////////////////////////////////////////////// - - " C/C++ template. - function! s:CFileTemplate() - let s:env = { - \ 'filename': expand('%:t'), - \ 'creation_date': strftime('%Y-%m-%d'), - \ 'year': strftime('%Y'), - \ 'copyright_owner': 'Jelly Pixel, Inc. All Rights Reserved.' - \} - - let l:template =<< trim EOS - /*================================================================================================== - File: ${filename} - Creation Date: ${creation_date} - Creator: Michael Campagnaro - Notice!: (C) Copyright ${year} by ${copyright_owner} - ================================================================================================*/ - - //////////////////////////////////////////////////////////////////////////////////////////////////// - // # Defines - //////////////////////////////////////////////////////////////////////////////////////////////////// - - //////////////////////////////////////////////////////////////////////////////////////////////////// - // # Globals - //////////////////////////////////////////////////////////////////////////////////////////////////// - - //////////////////////////////////////////////////////////////////////////////////////////////////// - // # Structs - //////////////////////////////////////////////////////////////////////////////////////////////////// - - //////////////////////////////////////////////////////////////////////////////////////////////////// - // # Macros - //////////////////////////////////////////////////////////////////////////////////////////////////// - - //////////////////////////////////////////////////////////////////////////////////////////////////// - // # Private API - //////////////////////////////////////////////////////////////////////////////////////////////////// - - //////////////////////////////////////////////////////////////////////////////////////////////////// - // # Public API - //////////////////////////////////////////////////////////////////////////////////////////////////// - -EOS - return map(l:template, { _, line -> substitute(line, '${\(.\{-}\)}', '\=get(s:env, submatch(1), submatch(1))', 'g') } ) - endfunction - - function! s:InsertCHeaderGates() - call append(0, '#pragma once') - "let l:gatename = substitute(toupper(expand("%:t")), '\\.', '_', 'g') - "call append(0, '#ifndef '. l:gatename) - "call append(line('$'), '#define '. l:gatename) - "call append(line('$'), '#endif') - endfunction - - " sh template - function! s:ShellScriptTemplate() - let l:template =<< trim EOS - #!/usr/bin/env bash - - if which tput >/dev/null 2>&1; then - ncolors=$(tput colors) - fi - if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then - RED="$(tput setaf 1)" - GREEN="$(tput setaf 2)" - YELLOW="$(tput setaf 3)" - BLUE="$(tput setaf 4)" - MAGENTA="$(tput setaf 5)" - CYAN="$(tput setaf 6)" - BOLD="$(tput bold)" - DIM="\e[2m" - NORMAL="$(tput sgr0)" - else - RED="" - GREEN="" - YELLOW="" - BLUE="" - MAGENTA="" - CYAN="" - BOLD="" - NORMAL="" - fi - - error() { - printf "${BOLD}${RED}$1${NORMAL}\n" - } - - abort() { - error "\nAborting..." - exit 1 - } - - set -e - - cwd=$PWD - - uname_s="$(uname -s)" - case "${uname_s}" in - Linux*) machine=Linux;; - Darwin*) machine=MacOS;; - CYGWIN*) machine=Cygwin;; - MINGW*) machine=MinGw;; - *) machine="UNKNOWN:${uname_s}" - esac - - printf "${YELLOW}Platform: $machine${NORMAL}\n" -EOS - return l:template - endfunction - - " Shell script template. - autocmd BufNewFile *.sh call append(0, s:ShellScriptTemplate()) - - " C/C++ file. - autocmd BufNewFile *.{c,cc,cpp,h,hpp,inl} call append(0, s:CFileTemplate()) - autocmd BufNewFile *.{h,hpp,inl} call s:InsertCHeaderGates() augroup END """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -641,7 +523,7 @@ cmap %/ %:p:h/ " order to only call it once for a group of saves I've had to remap the " various save commands to a function call. -function! s:CreateCtags() +function! CreateCtags() " Only allow one instance of ctags to run in this directory at any given time. let l:lock_file = "ctags.lock" if filereadable(l:lock_file) || filereadable("newtags") @@ -697,12 +579,12 @@ endfun " file using rv or whatever. :ReloadVimrcError function! DoSingleWrite() write! - call s:CreateCtags() + call CreateCtags() endfunction function! DoSingleWriteThenQuit() write! - call s:CreateCtags() + call CreateCtags() quit endfunction @@ -713,7 +595,7 @@ function! DoMultiWrite() bufdo wa " Restore the last buffer because it may have changed. exec "buffer " . l:current_buffer - call s:CreateCtags() + call CreateCtags() endfunction cnoreabbrev w :call DoSingleWrite() @@ -800,29 +682,6 @@ noremap v :e %:p:s,.h$,.X123X,:s,.cpp$,.h,:s,.X123X$,.cpp, " Replace all instances of the highlighted text with whatever you enter. nnoremap :%s///g -"//////////////////////////////////////////////////////////////// -" QUICKLY OPEN C++ SOURCE OR HEADER FILE -"//////////////////////////////////////////////////////////////// - -function! s:CompleteFilenameWithoutExtension(ArgLead, CmdLine, CursorPos) - " Returns a matching filename without the period that separates the name - " from the extension. - let l:file = substitute(glob(a:ArgLead.'*', 0, 0), "[\.].*", "", "*") - return l:file -endfunction - -" Custom command to open cpp and h files without typing an extension -"command! -nargs=+ -complete=custom,s:CompleteFilenameWithoutExtension "OpenCppSource exec ':e .cpp' -":ca c OpenCppSource -":ca C OpenCppSource - -"command! -nargs=+ -complete=custom,s:CompleteFilenameWithoutExtension "OpenCppHeader exec ':e .h' -":ca h OpenCppHeader -":ca H OpenCppHeader - -"command! -nargs=+ -complete=custom,s:CompleteFilenameWithoutExtension "OpenCppSourceAndHeader exec ':vsp | :e .h | :sp .cpp' -":ca b OpenCppSourceAndHeader -":ca B OpenCppSourceAndHeader "//////////////////////////////////////////////////////////////// " MULTIPURPOSE TAB KEY @@ -1533,7 +1392,7 @@ function! GlobalReplaceIt(confirm_replacement) range silent! exec 'source _replace_session.vim | !rm _replace_session.vim &>/dev/null' endif - call s:CreateCtags() + call CreateCtags() else call PrintError("Unable to search since you're not in a git repo!") endif