If you are working on Objective-C kode in VI the following functions and key mapping will allow you to quickly switch between the header and implementation file.
" Switch editing between" *.c and *.h files (C)" or" *.m and *.h files (ObjC)function! Flip_Extension()ifmatch(expand("%"),'\.m')>0let s:flipname = substitute(expand("%"),'\.m\(.*\)','.h\1',"")call LoadFile(s:flipname)elseifmatch(expand("%"),"\\.h")>0let s:flipname = substitute(expand("%"),'\.h\(.*\)','.m\1',"")if(filereadable(s:flipname))>0call LoadFile(s:flipname)elselet s:flipname = substitute(expand("%"),'\.h\(.*\)','.c\1',"")call LoadFile(s:flipname)endifelseifmatch(expand("%"),"\\.c")>0let s:flipname = substitute(expand("%"),'\.c\(.*\)','.h\1',"")call LoadFile(s:flipname)endif
endfun
" Find the filename in an existing buffer" if it exists open that buffer so you don't" lose your file position.function! LoadFile(filename)let s:bufname = bufname(a:filename)if(strlen(s:bufname))>0exe":buffer" s:bufnameelseexe":find " a:filename
endif
endfun
map<F4>:call Flip_Extension()<CR>
This entry was posted
on Tuesday, November 24th, 2009 at 1:40 pm and is filed under Mondo Kode.
You can follow any responses to this entry through the RSS 2.0 feed.
Both comments and pings are currently closed.