├── .github └── FUNDING.yml ├── .gitignore ├── CONTRIBUTING.markdown ├── README.markdown ├── doc └── rvm.txt └── plugin └── rvm.vim /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: tpope 2 | custom: ["https://www.paypal.me/vimpope"] 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /doc/tags 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.markdown: -------------------------------------------------------------------------------- 1 | See the contribution guidelines for 2 | [rails.vim](https://github.com/tpope/vim-rails/blob/HEAD/CONTRIBUTING.markdown). 3 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | # rvm.vim 2 | 3 | Want to use [RVM](http://rvm.io) with Vim? You don't 4 | need a plugin to do that: Just start Vim from your RVM enabled shell 5 | and it will work. But say you started MacVim from Launchpad, or you 6 | started Vim with one version of Ruby and now you want another. That's 7 | where rvm.vim comes in. 8 | 9 | :Rvm 1.9.2 10 | 11 | If you want to see the version that was chosen, use `use`: 12 | 13 | :Rvm use default 14 | 15 | If you leave off the version, it goes `.rvmrc` hunting relative to the 16 | current buffer. 17 | 18 | :Rvm 19 | :Rvm use 20 | 21 | If you really want to get crazy, you can make this happen automatically 22 | as you switch from buffer to buffer. 23 | 24 | :autocmd BufEnter * Rvm 25 | 26 | You can also invoke any old `rvm` command. 27 | 28 | :Rvm install 1.9.3 29 | 30 | Add `%{rvm#statusline()}` to `'statusline'` (or `'titlestring'`) to see 31 | the current Ruby version at all times. 32 | 33 | Last but not least, rvm.vim tells recent versions of [vim-ruby][] where your 34 | Ruby installs are located, so that it can set `'path'` in your Ruby buffers to 35 | reflect the nearest `.ruby-version` file. 36 | 37 | [vim-ruby]: https://github.com/vim-ruby/vim-ruby 38 | 39 | ## FAQ 40 | 41 | > RVM doesn't work in my Vim. 42 | 43 | You're using zsh on OS X Yosemite or earlier, aren't you? Move that stupid 44 | `/etc/zshenv` to `/etc/zprofile`, which is where it correctly lives on El 45 | Capitan. 46 | 47 | ## Self-Promotion 48 | 49 | Like rvm.vim? Follow the repository on 50 | [GitHub](https://github.com/tpope/vim-rvm) and vote for it on 51 | [vim.org](http://www.vim.org/scripts/script.php?script_id=4269). And if 52 | you're feeling especially charitable, follow [tpope](http://tpo.pe/) on 53 | [Twitter](http://twitter.com/tpope) and 54 | [GitHub](https://github.com/tpope). 55 | 56 | ## License 57 | 58 | Copyright (c) Tim Pope. Distributed under the same terms as Vim itself. 59 | See `:help license`. 60 | -------------------------------------------------------------------------------- /doc/rvm.txt: -------------------------------------------------------------------------------- 1 | *rvm.txt* Switch Ruby versions from inside Vim 2 | 3 | Author: Tim Pope 4 | License: Same terms as Vim itself (see |license|) 5 | 6 | This plugin is only available if 'compatible' is not set. 7 | 8 | COMMANDS *:Rvm* 9 | 10 | :Rvm Set the current Ruby version to the version found in 11 | the .rvmrc for the current buffer. If no .rvmrc is 12 | found, set it to the default version. 13 | 14 | :Rvm {version} Set the current Ruby version to {version}. 15 | 16 | :Rvm use [version] As above, but echo the version chosen. 17 | 18 | :Rvm {command} Run rvm with arbitrary arguments. 19 | 20 | To automatically switch Ruby versions when switching buffers: 21 | > 22 | autocmd BufEnter * Rvm 23 | 24 | STATUSLINE *rvm#statusline()* 25 | 26 | Add rvm#statusline() to 'statusline' (or 'titlestring') to see the current 27 | version in your statusline (or title bar). 28 | 29 | ABOUT *rvm-about* 30 | 31 | Grab the latest version or report a bug on GitHub: 32 | 33 | https://github.com/tpope/vim-rvm 34 | 35 | vim:tw=78:et:ft=help:norl: 36 | -------------------------------------------------------------------------------- /plugin/rvm.vim: -------------------------------------------------------------------------------- 1 | " rvm.vim - Switch Ruby versions from inside Vim 2 | " Maintainer: Tim Pope 3 | " Version: 1.0 4 | 5 | if exists('g:loaded_rvm') || v:version < 700 || &cp 6 | finish 7 | endif 8 | 9 | if !exists('$rvm_path') && isdirectory(expand('~/.rvm')) 10 | let $rvm_path = expand('~/.rvm') 11 | let $PATH = $rvm_path . '/bin' . ':' . $PATH 12 | endif 13 | 14 | if !exists('$rvm_path') 15 | finish 16 | endif 17 | 18 | let g:loaded_rvm = 1 19 | 20 | " Utility {{{1 21 | 22 | function! s:shellesc(arg) abort 23 | if a:arg =~ '^[A-Za-z0-9_/.-]\+$' 24 | return a:arg 25 | else 26 | return shellescape(a:arg) 27 | endif 28 | endfunction 29 | 30 | " }}}1 31 | " :Rvm {{{1 32 | 33 | function! rvm#buffer_path_identifier(...) 34 | let name = bufname(a:0 ? a:1 : '%') 35 | if name ==# '' 36 | let path = '.' 37 | elseif isdirectory(name) 38 | let path = name 39 | elseif !isdirectory(resolve(fnamemodify(name, ":p:h"))) 40 | let path = '.' 41 | else 42 | let path = fnamemodify(name, ':h') 43 | endif 44 | 45 | let path_identifier = system('rvm tools path-identifier '.s:shellesc(path)) 46 | return split(path_identifier)[-1] 47 | endfunction 48 | 49 | function! s:Rvm(bang,...) abort 50 | let path = split($PATH,':') 51 | call filter(path, 'v:val[0:strlen($rvm_path)] !=# $rvm_path."/"') 52 | 53 | if a:0 && a:0 < 3 && a:1 ==# 'use' 54 | let use = 1 55 | let args = a:000[1:-1] 56 | else 57 | let use = 0 58 | let args = copy(a:000) 59 | endif 60 | 61 | if len(args) > 1 || (len(args) == 1 && args[0] !~ '^\%(@\|\d\|default\|j\=ruby\|goruby\|rbx\|ree\|kiji\|maglev\|ironruby\|system\)' && !use) 62 | return '!rvm '.join(map(copy(a:000), 's:shellesc(v:val)'), ' ') 63 | elseif !empty(args) && args[-1] ==# 'system' 64 | let desired = 'system' 65 | elseif !empty(args) 66 | let desired = system('rvm tools strings '.s:shellesc(args[0]))[0:-2] 67 | elseif use || !exists('b:rvm_string') 68 | let desired = rvm#buffer_path_identifier() 69 | else 70 | let desired = b:rvm_string 71 | endif 72 | 73 | if desired ==# 'system' 74 | let $RUBY_VERSION = '' 75 | let $MY_RUBY_HOME = '' 76 | let $IRBRC = expand('~/.irbrc') 77 | let $PATH = join([$rvm_path.'/bin'] + path,':') 78 | let $GEM_HOME = system('env -i PATH="'.$PATH.'" ruby -rrubygems -e "print Gem.dir"') 79 | let $GEM_PATH = system('env -i PATH="'.$PATH.'" ruby -rrubygems -e "print Gem.path.join(%{:})"') 80 | if use 81 | return 'echomsg "Using system ruby"' 82 | else 83 | return '' 84 | endif 85 | endif 86 | 87 | let ver = matchstr(desired,'[^@]*') 88 | let gemset = matchstr(desired,'@.*') 89 | if ver ==# '' 90 | return 'echoerr "Ruby version not found"' 91 | endif 92 | if !isdirectory($rvm_path . '/rubies/' . ver) 93 | if $rvm_install_on_use_flag 94 | execute 'Rvm install '.ver 95 | else 96 | return 'echoerr "Ruby version not installed: :Rvm install ".'.string(ver) 97 | endif 98 | endif 99 | let b:rvm_string = desired 100 | 101 | let $RUBY_VERSION = ver 102 | let $GEM_HOME = $rvm_path . '/gems/' . $RUBY_VERSION . gemset 103 | let $MY_RUBY_HOME = $rvm_path . '/rubies/' . $RUBY_VERSION 104 | let $IRBRC = $MY_RUBY_HOME . '/.irbrc' 105 | 106 | let gemsets = [$GEM_HOME, $rvm_path . '/gems/' . $RUBY_VERSION . '@global'] 107 | 108 | let $GEM_PATH = join(gemsets, ':') 109 | let $PATH = join( 110 | \ map(gemsets,'v:val."/bin"') + 111 | \ [$MY_RUBY_HOME.'/bin'] + 112 | \ [$rvm_path.'/bin'] + 113 | \ path, ':') 114 | if use 115 | return 'echomsg "Using " . $GEM_HOME' 116 | else 117 | return '' 118 | endif 119 | endfunction 120 | 121 | function! s:Complete(A,L,P) 122 | if a:A =~# '@' 123 | let requested = matchstr(a:A,'^[^@]*') 124 | let desired = system('rvm tools strings '.s:shellesc(requested))[0:-2] 125 | let all = split(glob($rvm_path.'/gems/'.desired.'@*'),"\n") 126 | call map(all,"v:val[strlen($rvm_path)+6:-1]") 127 | call map(all,'substitute(v:val,"^[^@]*",requested,"")') 128 | else 129 | let all = split(glob($rvm_path.'/rubies/*'),"\n") 130 | call map(all,"v:val[strlen($rvm_path)+8:-1]") 131 | if a:A !~# '^r' 132 | call map(all,'substitute(v:val,"^ruby-\\ze\\d","","")') 133 | endif 134 | endif 135 | return join(all,"\n") 136 | endfunction 137 | 138 | command! -bar -nargs=* -complete=custom,s:Complete Rvm :execute s:Rvm(0,) 139 | 140 | " }}}1 141 | " Statusline {{{1 142 | 143 | function! rvm#string() 144 | return matchstr($GEM_HOME,'[^/]*$') 145 | endfunction 146 | 147 | function! rvm#statusline() 148 | return substitute('['.rvm#string().']','^\[\]$','','') 149 | endfunction 150 | 151 | function! rvm#statusline_ft_ruby() 152 | if &filetype ==# 'ruby' 153 | return rvm#statusline() 154 | else 155 | return '' 156 | endif 157 | endfunction 158 | 159 | " }}}1 160 | " Load path {{{1 161 | 162 | function! rvm#ruby_version_paths() abort 163 | let dict = {} 164 | for entry in split(glob("$rvm_path/rubies/ruby-*")) 165 | let ver = matchstr(entry, '/rubies/ruby-\zs.*') 166 | let paths = ver =~# '^1.[0-8]' ? ['.'] : [] 167 | let paths += split($RUBYLIB, ':') 168 | let site_ruby_arch = glob(entry . '/lib/ruby/site_ruby/*.*/*-*') 169 | if empty(site_ruby_arch) || site_ruby_arch =~# "\n" 170 | continue 171 | endif 172 | let arch = fnamemodify(site_ruby_arch, ':t') 173 | let minor = fnamemodify(site_ruby_arch, ':h:t') 174 | let paths += [ 175 | \ entry . '/lib/ruby/site_ruby/' . minor, 176 | \ entry . '/lib/ruby/site_ruby/' . minor . '/' . arch, 177 | \ entry . '/lib/ruby/site_ruby', 178 | \ entry . '/lib/ruby/vendor_ruby/' . minor, 179 | \ entry . '/lib/ruby/vendor_ruby/' . minor . '/' . arch, 180 | \ entry . '/lib/ruby/vendor_ruby', 181 | \ entry . '/lib/ruby/' . minor, 182 | \ entry . '/lib/ruby/' . minor . '/' . arch] 183 | let dict[ver] = paths 184 | endfor 185 | return dict 186 | endfunction 187 | 188 | if !exists('g:ruby_version_paths') 189 | let g:ruby_version_paths = {} 190 | endif 191 | 192 | call extend(g:ruby_version_paths, rvm#ruby_version_paths(), 'keep') 193 | 194 | " }}}1 195 | 196 | " vim:set sw=2 sts=2: 197 | --------------------------------------------------------------------------------