Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function! RubyEndToken ()
- let current_line = getline( '.' )
- let braces_at_end = '{\s*\(|\(,\|\s\|\w\)*|\s*\)\?$'
- let brackets_at_end = '[\s*\(|\(,\|\s\|\w\)*|\s*\)\?$'
- let stuff_without_do = '^\s*\(class\|if\|unless\|begin\|case\|for\|module\|while\|until\|def\)'
- let with_do = 'do\s*\(|\(,\|\s\|\w\)*|\s*\)\?$'
- if match(current_line, braces_at_end) >= 0
- return "\<CR>}\<C-O>O"
- elseif match(current_line, brackets_at_end) >= 0
- return "\<CR>\1\<C-O>O"
- elseif match(current_line, stuff_without_do) >= 0
- return "\<CR>end\<C-O>O"
- elseif match(current_line, with_do) >= 0
- return "\<CR>end\<C-O>O"
- else
- return "\<CR>"
- endif
- endfunction
- autocmd FileType ruby,eruby inoremap <buffer> <CR> <C-R>=RubyEndToken()<CR>
Add Comment
Please, Sign In to add comment