Skip to content

Commit

Permalink
Version 0.1: Initial upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Tanzler authored and vim-scripts committed Oct 18, 2010
0 parents commit c4d8079
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This is a mirror of http://www.vim.org/scripts/script.php?script_id=290

Map '%' to jump from one keyword to its corresponding 'end' in Ruby files. Inspired by 'matchit.vim' that comes with Vim.


70 changes: 70 additions & 0 deletions plugin/ruby-matchit.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
" FILE: "/home/johannes/ruby.vim"
" Last Modification: "Mon, 06 May 2002 23:42:11 +0200 (johannes)"
" Additional settings for Ruby
" Johannes Tanzler, <jtanzler@yline.com>

" Matchit for Ruby: '%' {{{
"
" This function isn't very sophisticated. It just takes care of indentation.
" (I've written it, because I couldn't extend 'matchit.vim' to handle Ruby
" files correctly (that's because everything in Ruby ends with 'end' -- no
" 'endif', 'endclass' etc.))
"
" If you're on the line `if x', then the cursor will jump to the next line
" with the same indentation as the if-clause. The same is true for a whole
" bunch of keywords -- see below for details.
"
" Since brave programmers use indentation, this will work for most of you, I
" hope. At least, it works for me. ;-)
" }}}
function! s:Ruby_Matchit()

" use default matching for parenthesis, brackets and braces:
if strpart(getline("."), col(".")-1, 1) =~ '(\|)\|{\|}\|\[\|\]'
normal \\\\\
endif

normal ^
sil! let curr_word = expand('<cword>')
if curr_word == ""
return
endif

let curr_line = line(".")
let spaces = strlen(matchstr(getline("."), "^\\s*"))

if curr_word =~ '\<end\>'
while 1
normal k
if strlen(matchstr(getline("."), "^\\s*")) == spaces
\&& getline(".") !~ "^\\s*$"
\&& getline(".") !~ "^#"
normal ^
break
elseif line(".") == 1
exe 'normal ' . curr_line . 'G'
break
endif
endwhile
elseif curr_word =~ '\<\(if\|unless\|elsif\|else\|case\|when\|while\|'
\.'until\|def\|\|module\|class\)\>'
while 1
normal j
if strlen(matchstr(getline("."), "^\\s*")) == spaces
\&& getline(".") !~ "^\\s*$"
\&& getline(".") !~ "^#"
normal ^
break
elseif line(".") == line("$")
exe 'normal ' . curr_line . 'G'
break
endif
endwhile
endif

endfunction

nnoremap <buffer> \\\\\ %
nnoremap <buffer> % :call <SID>Ruby_Matchit()<CR>

0 comments on commit c4d8079

Please sign in to comment.