changeset 11:d428a965f322

Added a mapping/function to edit a file's other part (header/impl).
author Brian Neal <bgneal1@rockwellcollins.com>
date Mon, 04 Feb 2013 14:12:18 -0600
parents b113527fa5d1
children 0c225d280b06
files vim/.vimrc
diffstat 1 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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()<CR>
+
 " Pathogen support
 call pathogen#infect()