summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Braendli <matthias.braendli@u-blox.com>2015-10-28 11:30:22 +0100
committerMatthias Braendli <matthias.braendli@u-blox.com>2015-10-28 11:30:22 +0100
commitd247768f2669f56bc40d4aa09311e9dc55773292 (patch)
tree1ae80e6d1a52ab02cb64d3388541ac206c5b1c34
parent2a6a9134720397cca5e78c3a352d2d93ef31cc59 (diff)
downloadvimrc-d247768f2669f56bc40d4aa09311e9dc55773292.tar.gz
vimrc-d247768f2669f56bc40d4aa09311e9dc55773292.tar.bz2
vimrc-d247768f2669f56bc40d4aa09311e9dc55773292.zip
Update header to code flip script
-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