From 0faae5ec206be7c1963449a38ea9278b333254f1 Mon Sep 17 00:00:00 2001 From: Michael Campagnaro Date: Thu, 13 Jul 2017 16:03:28 -0400 Subject: [PATCH] Add vim command for opening cpp source and header files --- vimrc | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/vimrc b/vimrc index 6bc5183..2c1a426 100644 --- a/vimrc +++ b/vimrc @@ -316,6 +316,9 @@ nmap x :x :ca W w :ca Q q +" lowercase the e (have a habit of making it uppercase) +:ca E e + command! Q q " Bind :Q to :q command! Qall qall " Disable Ex mode @@ -380,6 +383,30 @@ nnoremap pp :silent !open -a Marked.app '%:p' " Switch between C++ source and header files map v :e %:p:s,.h$,.X123X,:s,.cpp$,.h,:s,.X123X$,.cpp, +"//////////////////////////////////////////////////////////////// +" 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 execute ':e .cpp' +:ca c OpenCppSource +:ca C OpenCppSource + +command! -nargs=+ -complete=custom,s:CompleteFilenameWithoutExtension OpenCppHeader execute ':e .h' +:ca h OpenCppHeader +:ca H OpenCppHeader + +command! -nargs=+ -complete=custom,s:CompleteFilenameWithoutExtension OpenCppSourceAndHeader execute ':vsp | :e .h | :sp .cpp' +:ca b OpenCppSourceAndHeader +:ca B OpenCppSourceAndHeader + "//////////////////////////////////////////////////////////////// " MULTIPURPOSE TAB KEY "////////////////////////////////////////////////////////////////