# HG changeset patch # User Brian Neal # Date 1360008738 21600 # Node ID d428a965f32201ce984f1b4e9eb4f085b5915825 # Parent b113527fa5d188a59464502b8a304615484e1773 Added a mapping/function to edit a file's other part (header/impl). diff -r b113527fa5d1 -r d428a965f322 vim/.vimrc --- a/vim/.vimrc Wed Dec 19 19:11:38 2012 -0600 +++ b/vim/.vimrc Mon Feb 04 14:12:18 2013 -0600 @@ -110,5 +110,33 @@ " Format paragraph nnoremap ,p gqip +function BgnSwitchPart() +python << EOF +import vim, os.path, sys +fname = vim.current.buffer.name +base, ext = os.path.splitext(fname) +headers = ['.h', '.hxx'] +impls = ['.cpp', '.cxx', '.cc', '.c'] +new_exts = None +if ext in headers: + new_exts = impls +elif ext in impls: + new_exts = headers + +if new_exts: + for ext in new_exts: + new_fname = base + ext + if os.path.exists(new_fname): + vim.command(":e %s" % new_fname) + break + else: + sys.stderr.write("Could not find other part\n") +else: + sys.stderr.write("Uknown extension %s" % ext) +EOF +endfunction + +nnoremap ,s :call BgnSwitchPart() + " Pathogen support call pathogen#infect()