aboutsummaryrefslogtreecommitdiffstats
path: root/dotvimrc
diff options
context:
space:
mode:
Diffstat (limited to 'dotvimrc')
-rw-r--r--dotvimrc68
1 files changed, 35 insertions, 33 deletions
diff --git a/dotvimrc b/dotvimrc
index 3d108bd..86f3694 100644
--- a/dotvimrc
+++ b/dotvimrc
@@ -173,43 +173,45 @@ autocmd BufNewFile,BufRead *.md set filetype=markdown
set nostartofline
-"F4 switches from C source .c to header .h file
-function! MPB_LoadFile(filename)
- let s:bufname = bufname(a:filename)
- if (strlen(s:bufname)) > 0
- " File already in a buffer
- exe ":buffer" s:bufname
- else
- " Must open file first
- exe ":e " a:filename
- endif
-endfun
-
-
+"Leader-f switches from C source .c to header .h file
+"It automatically detects .cpp <-> .h
+" .c <-> .h
+" .cpp <-> .hpp
function! MPB_Flip_Ext()
- " Switch editing between .c(XYZ) and .h(XYZ) files.
- if match(expand("%"),'\.c') > 0
- let s:flipname = substitute(expand("%"),'\.c\(.*\)','.h\1',"")
- exe ":call MPB_LoadFile(s:flipname)"
- elseif match(expand("%"),'\.h') > 0
- let s:flipname = substitute(expand("%"),'\.h\(.*\)','.c\1',"")
- exe ":call MPB_LoadFile(s:flipname)"
- endif
-endfun
-
-function! MPB_Flip_Cpp_H()
- " Switch editing between .c(XYZ) and .h(XYZ) files.
- if match(expand("%"),'\.cpp') > 0
- let s:flipname = substitute(expand("%"),'\.cpp','.h',"")
- exe ":call MPB_LoadFile(s:flipname)"
- elseif match(expand("%"),'\.h') > 0
- let s:flipname = substitute(expand("%"),'\.h','.cpp',"")
- exe ":call MPB_LoadFile(s:flipname)"
- endif
+python << endpython
+import vim
+import os.path
+
+def loadfile(filename):
+ vim.command("e {}".format(filename))
+
+currentfile = vim.eval('expand("%")')
+
+print("Current file is {}".format(currentfile))
+
+if currentfile.endswith(".c"):
+ loadfile(currentfile[:-2] + ".h")
+elif currentfile.endswith(".h"):
+ basename = currentfile[:-2]
+ if os.path.exists(basename + ".cpp"):
+ loadfile(basename + ".cpp")
+ else:
+ loadfile(basename + ".c")
+elif currentfile.endswith(".cpp"):
+ basename = currentfile[:-4]
+ if os.path.exists(basename + ".h"):
+ loadfile(basename + ".h")
+ else:
+ loadfile(basename + ".hpp")
+elif currentfile.endswith(".hpp"):
+ basename = currentfile[:-4]
+ loadfile(basename + ".cpp")
+
+endpython
endfun
noremap <F4> :call MPB_Flip_Ext()<CR>
-noremap <F3> :call MPB_Flip_Cpp_H()<CR>
+noremap <Leader>f :call MPB_Flip_Ext()<CR>
"Show trailing whitespace
highlight ExtraWhitespace ctermbg=darkgreen guibg=#344011