Created
March 12, 2012 23:49
-
-
Save nornagon/2025487 to your computer and use it in GitHub Desktop.
Open related file in vim (a la Sublime Text 2's Alt-O)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Opens a file in [path/to/current_file.*] that isn't already open. | |
function! RelatedFiles() | |
return filter(split(globpath(expand('%:h'), expand('%:t:r').'.*')), '!bufloaded(v:val)') | |
endfunction | |
function! OpenRelatedFile() | |
let files = RelatedFiles() | |
if len(files) > 0 | |
" always open .h files on the left. | |
if match(files[0], "\.h$") >= 0 | |
exec 'lefta vsplit '.files[0] | |
else | |
exec 'rightb vsplit '.files[0] | |
endif | |
endif | |
endfunction | |
nmap ^[o :call OpenRelatedFile()<CR> | |
nmap <M-o> :call OpenRelatedFile()<CR> | |
nmap ø :call OpenRelatedFile()<CR> " OSX is adorable | |
" Alt keys can be fiddly; you might need to replace <M-o> above with ^[o (literal ^[, type Ctrl-V Alt-O) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment