[PATCH] Suggestion for updated ftplugin/ruby.vim

Nikolai Weibull mailing-lists.vim-ruby-development at rawuncut.elitemail.org
Sun Aug 28 12:39:43 EDT 2005

Doug Kearns wrote:

> On Sun, Aug 28, 2005 at 01:53:52PM +0200, Nikolai Weibull wrote:

> > These are other additions to ftplugin/ruby.vim found in Ned Konz script.
> > I think that they make sense in almost any setting, so they should go in
> > the distribution.  Comments before I commit?,

> Because I'm lazy can you point me to Ned's script?


I am, however, doubtful about setting iskeyword to include ':'.  The
reason for doing so is that we have stuff like ConstantA::ConstantB kind
of stuff and that we want to be able to treat that as one thing on
occasion.  I think, however, that this causes too many issues with other
stuff to be reasonable.

> You might want to search the archives since this came up when Gavin was
> first organising the project. I don't remember the details but he was
> certainly conservative.

It seems it hasn't changed since

> That said, given your 100 odd ftplugins you are the master... ;-)

I'm taking Vim one step closer to becoming Emacs per file :-D.

Here's another thing I've been playing with, but I have the feeling that
electricity isn't something that most Vim-users appreciate...What do you
think?  (Btw, that regex isn't quite right...I'll have to fix that.)

inoremap <buffer> <CR> <C-O>:call <SID>CompleteStatement()<CR><CR>

function! s:CompleteStatement()
  " TODO: we can check contents of ". register to make sure that they were
  " inserted while typing here...
  if getline('.') =~ '^\s*\%(begin\|case\|class\|def\|for\|if\|module\|unless\|until\|while\)\>\|do\%(\s*|[^|]*|\s*\)\=$'
    let n = indent('.')
    let ind = ''
    let i = 0
    while i < n
      let ind .= ' '
      let i += 1
    call append(line('.'), ind . 'end')

It automatically inserts a matching 'end' when necessary.

Totally off-topic:

By the way, do you know why pasting text selected in conkeror is so

Nikolai Weibull: now available free of charge at http://bitwi.se/!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
-------------- next part --------------
" Vim filetype plugin
" Language:	Ruby
" Maintainer:	Gavin Sinclair <gsinclair at soyabean.com.au>
" Info:         $Id: ruby.vim,v 1.7 2004/01/10 23:06:11 gsinclair Exp $
" URL:          http://vim-ruby.sourceforge.net
" Anon CVS:     See above site 
" Licence:      GPL (http://www.gnu.org)
" Disclaimer: 
"    This program is distributed in the hope that it will be useful,
"    but WITHOUT ANY WARRANTY; without even the implied warranty of
"    GNU General Public License for more details.
" ----------------------------------------------------------------------------
" Matchit support thanks to Ned Konz.  See his ftplugin/ruby.vim at
"   http://bike-nomad.com/vim/ruby.vim.
" ----------------------------------------------------------------------------

" Only do this when not done yet for this buffer
if (exists("b:did_ftplugin"))
let b:did_ftplugin = 1

let s:cpo_save = &cpo
set cpo&vim

" Matchit support
if exists("loaded_matchit") && !exists("b:match_words")
  let b:match_ignorecase = 0
  let b:match_words =
     \ '\%(\%(\%(^\|[;=]\)\s*\)\@<=\%(class\|module\|while\|begin\|until' .
     \ '\|for\|if\|unless\|def\|case\)\|\<do\)\>:' .
     \ '\<\%(else\|elsif\|ensure\|rescue\|when\)\>:' .
     \ '\%(^\|[^.]\)\@<=\<end\>'
  let b:match_skip =
     \ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" .
     \ "\<ruby\%(String\|StringDelimiter\|ASCIICode\|Interpolation\|" .
     \ "NoInterpolation\|Escape\|Comment\|Documentation\)\>'"


setlocal formatoptions-=t formatoptions+=croql

setlocal include=^\\s*\\<\\(load\\\|\w*require\\)\\>
setlocal includeexpr=substitute(substitute(v:fname,'::','/','g'),'$','.rb','')
setlocal suffixesadd=.rb

setlocal define=^\\s*def

setlocal comments=:#
setlocal commentstring=#\ %s

if !exists("s:rubypath")
  if executable("ruby")
    if &shellxquote == "'"
      let s:rubypath = system('ruby -e "print $:.join(%q{,})"' )
      let s:rubypath = system("ruby -e 'print $:.join(%q{,})'" )
    let s:rubypath = substitute(s:rubypath,',.$',',,','')
    " If we can't call ruby to get its path, just default to using the
    " current directory and the directory of the current file.
    let s:rubypath = ".,,"

let &l:path = s:rubypath

let b:undo_ftplugin = "setl fo< inc< inex< sua< def< com< cms< path< "
      \ "| unlet! b:match_ignorecase b:match_words b:match_skip"

let &cpo = s:cpo_save
unlet s:cpo_save

" Instructions for enabling "matchit" support:
" 1. Look for the latest "matchit" plugin at
"         http://www.vim.org/scripts/script.php?script_id=39
"    It is also packaged with Vim, in the $VIMRUNTIME/macros directory.
" 2. Copy "matchit.txt" into a "doc" directory (e.g. $HOME/.vim/doc).
" 3. Copy "matchit.vim" into a "plugin" directory (e.g. $HOME/.vim/plugin).
" 4. Ensure this file (ftplugin/ruby.vim) is installed.
" 5. Ensure you have this line in your $HOME/.vimrc:
"         filetype plugin on
" 6. Restart Vim and create the matchit documentation:
"         :helptags ~/.vim/doc
"    Now you can do ":help matchit", and you should be able to use "%" on Ruby
"    keywords.  Try ":echo b:match_words" to be sure.
" Thanks to Mark J. Reed for the instructions.  See ":help vimrc" for the
" locations of plugin directories, etc., as there are several options, and it
" differs on Windows.  Email gsinclair at soyabean.com.au if you need help.

" vim: sw=2 sts=2 ts=8 ff=unix:

More information about the vim-ruby-devel mailing list