Skip to content

Instantly share code, notes, and snippets.

@nkuln
Created March 22, 2013 10:06
Show Gist options
  • Save nkuln/5220255 to your computer and use it in GitHub Desktop.
Save nkuln/5220255 to your computer and use it in GitHub Desktop.
Switch between C++ source/test/header in Vim
"switch between .h / -inl.h / .cc / .py / .js / _test.* / _unittest.* with ,h
",i ,c ,p ,j ,t ,u
""(portion from old mail from David Reiss)
let pattern = '\(\(_\(unit\)\?test\)\?\.\(cc\|js\|py\)\|\(-inl\)\?\.h\)$'
nmap ,c :e <C-R>=substitute(expand("%"), pattern, ".cc", "")<CR><CR>
nmap ,h :e <C-R>=substitute(expand("%"), pattern, ".h", "")<CR><CR>
nmap ,i :e <C-R>=substitute(expand("%"), pattern, "-inl.h", "")<CR><CR>
nmap ,t :e <C-R>=substitute(expand("%"), pattern, "_test.", "") . substitute(expand("%:e"), "h", "cc", "")<CR><CR>
nmap ,u :e <C-R>=substitute(expand("%"), pattern, "_unittest.", "") . substitute(expand("%:e"), "h", "cc", "")<CR><CR>
nmap ,p :e <C-R>=substitute(expand("%"), pattern, ".py", "")<CR><CR>
nmap ,j :e <C-R>=substitute(expand("%"), pattern, ".js", "")<CR><CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment