├── .gitignore
├── .github
└── FUNDING.yml
├── doc
└── rbenv.txt
├── README.markdown
└── plugin
└── rbenv.vim
/.gitignore:
--------------------------------------------------------------------------------
1 | doc/tags
2 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: tpope
2 | custom: ["https://www.paypal.me/vimpope"]
3 |
--------------------------------------------------------------------------------
/doc/rbenv.txt:
--------------------------------------------------------------------------------
1 | *rbenv.txt* Support for rbenv
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 and rbenv is in the
7 | $PATH.
8 |
9 | COMMANDS *:Rbenv*
10 |
11 | :Rbenv [args] Invoke an rbenv command. Includes tab complete.
12 |
13 | :Rbenv shell [version] Set or show the Vim-specific Ruby version.
14 |
15 | ABOUT *rbenv-about*
16 |
17 | Grab the latest version or report a bug on GitHub:
18 |
19 | https://github.com/tpope/vim-rbenv
20 |
21 | vim:tw=78:et:ft=help:norl:
22 |
--------------------------------------------------------------------------------
/README.markdown:
--------------------------------------------------------------------------------
1 | # rbenv.vim
2 |
3 | This simple plugin provides a `:Rbenv` command that wraps `!rbenv` with tab
4 | complete. It also tells recent versions of [vim-ruby][] where your Ruby
5 | installs are located, so that it can set `'path'` and [`'tags'`][rbenv-ctags]
6 | in your Ruby buffers to reflect the nearest `.ruby-version` file.
7 |
8 | Bonus: [projectionist.vim][] support for rbenv plugins.
9 |
10 | [vim-ruby]: https://github.com/vim-ruby/vim-ruby
11 | [rbenv-ctags]: https://github.com/tpope/rbenv-ctags
12 | [projectionist.vim]: https://github.com/tpope/vim-projectionist
13 |
14 | ## Installation
15 |
16 | If you don't have a preferred installation method, I recommend
17 | installing [pathogen.vim](https://github.com/tpope/vim-pathogen), and
18 | then simply copy and paste:
19 |
20 | cd ~/.vim/bundle
21 | git clone git://github.com/tpope/vim-rbenv.git
22 |
23 | ## FAQ
24 |
25 | > My Vim insists on using the system Ruby.
26 |
27 | You're using zsh on OS X, aren't you? Here are some things to try:
28 |
29 | * Move `/etc/zshenv` to `/etc/zprofile`, if you're on Yosemite or earlier.
30 | * Set your `PATH` in `~/.zprofile` instead of `~/.zshrc` or `~/.zshenv`.
31 |
32 | ## Self-Promotion
33 |
34 | Like rbenv.vim? Follow the repository on
35 | [GitHub](https://github.com/tpope/vim-rbenv) and vote for it on
36 | [vim.org](http://www.vim.org/scripts/script.php?script_id=4455). And if
37 | you're feeling especially charitable, follow [tpope](http://tpo.pe/) on
38 | [Twitter](http://twitter.com/tpope) and
39 | [GitHub](https://github.com/tpope).
40 |
41 | ## License
42 |
43 | Copyright (c) Tim Pope. Distributed under the same terms as Vim itself.
44 | See `:help license`.
45 |
--------------------------------------------------------------------------------
/plugin/rbenv.vim:
--------------------------------------------------------------------------------
1 | " rbenv.vim - rbenv support
2 | " Maintainer: Tim Pope
3 | " Version: 1.1
4 |
5 | if exists("g:loaded_rbenv") || v:version < 700 || &cp || !executable('rbenv')
6 | finish
7 | endif
8 | let g:loaded_rbenv = 1
9 |
10 | command! -bar -nargs=* -complete=custom,s:Complete Rbenv
11 | \ if get([], 0, '') ==# 'shell' |
12 | \ exe s:shell() |
13 | \ else |
14 | \ exe '!rbenv ' . |
15 | \ call extend(g:ruby_version_paths, s:ruby_version_paths(), 'keep') |
16 | \ endif
17 |
18 | function! s:shell(_, ...)
19 | if !a:0
20 | if empty($RBENV_VERSION)
21 | echo 'rbenv.vim: no shell-specific version configured'
22 | else
23 | echo $RBENV_VERSION
24 | endif
25 | return ''
26 | elseif a:1 ==# '--unset'
27 | let $RBENV_VERSION = ''
28 | elseif !isdirectory(s:rbenv_root() . '/versions/' . a:1)
29 | echo 'rbenv.vim: version `' . a:1 . "' not installed"
30 | else
31 | let $RBENV_VERSION = a:1
32 | endif
33 | call s:set_paths()
34 | if &filetype ==# 'ruby'
35 | set filetype=ruby
36 | endif
37 | return ''
38 | endfunction
39 |
40 | function! s:Complete(A, L, P)
41 | if a:L =~# ' .* '
42 | return system("rbenv completions".matchstr(a:L, ' .* '))
43 | else
44 | return system("rbenv commands")
45 | endif
46 | endfunction
47 |
48 | function! s:rbenv_root()
49 | return empty($RBENV_ROOT) ? expand('~/.rbenv') : $RBENV_ROOT
50 | endfunction
51 |
52 | function! s:ruby_version_paths() abort
53 | let dict = {}
54 | let root = s:rbenv_root() . '/versions/'
55 | for entry in split(glob(root.'*'))
56 | let ver = entry[strlen(root) : -1]
57 | let paths = ver =~# '^1.[0-8]' ? ['.'] : []
58 | let paths += split($RUBYLIB, ':')
59 | let site_ruby_arch = glob(entry . '/lib/ruby/site_ruby/*.*/*-*')
60 | if empty(site_ruby_arch) || site_ruby_arch =~# "\n"
61 | continue
62 | endif
63 | let arch = fnamemodify(site_ruby_arch, ':t')
64 | let minor = fnamemodify(site_ruby_arch, ':h:t')
65 | let paths += [
66 | \ entry . '/lib/ruby/site_ruby/' . minor,
67 | \ entry . '/lib/ruby/site_ruby/' . minor . '/' . arch,
68 | \ entry . '/lib/ruby/site_ruby',
69 | \ entry . '/lib/ruby/vendor_ruby/' . minor,
70 | \ entry . '/lib/ruby/vendor_ruby/' . minor . '/' . arch,
71 | \ entry . '/lib/ruby/vendor_ruby',
72 | \ entry . '/lib/ruby/' . minor,
73 | \ entry . '/lib/ruby/' . minor . '/' . arch]
74 | let dict[ver] = paths
75 | endfor
76 | return dict
77 | endfunction
78 |
79 | if !exists('g:ruby_version_paths')
80 | let g:ruby_version_paths = {}
81 | endif
82 |
83 | function! s:set_paths() abort
84 | call extend(g:ruby_version_paths, s:ruby_version_paths(), 'keep')
85 | if !empty($RBENV_VERSION)
86 | let ver = $RBENV_VERSION
87 | elseif filereadable(s:rbenv_root() . '/version')
88 | let ver = get(readfile(s:rbenv_root() . '/version', '', 1), 0, '')
89 | else
90 | return
91 | endif
92 | if has_key(g:ruby_version_paths, ver)
93 | let g:ruby_default_path = g:ruby_version_paths[ver]
94 | else
95 | unlet! g:ruby_default_path
96 | endif
97 | endfunction
98 |
99 | call s:set_paths()
100 |
101 | function! s:projectionist_detect() abort
102 | let root = s:rbenv_root() . '/plugins/'
103 | let file = get(g:, 'projectionist_file', get(b:, 'projectionist_file', ''))
104 | if file[0 : len(root)-1] ==# root
105 | call projectionist#append(root . matchstr(file, '[^/]\+', len(root)), {
106 | \ "bin/rbenv-*": {"command": "command", "template": [
107 | \ '#!/usr/bin/env bash',
108 | \ '#',
109 | \ '# Summary:',
110 | \ '#',
111 | \ '# Usage: rbenv {}',
112 | \ ]},
113 | \ "etc/rbenv.d/*.bash": {"command": "hook"}})
114 | endif
115 | endfunction
116 |
117 | augroup rbenv
118 | autocmd!
119 | autocmd User ProjectionistDetect call s:projectionist_detect()
120 | augroup END
121 |
122 | " vim:set et sw=2:
123 |
--------------------------------------------------------------------------------