1
0
mirror of https://github.com/xlogerais/config-vim synced 2024-11-10 00:21:41 +01:00
config-vim/after/ftplugin/ruby/utils.vim
Xavier Logerais (Numericable - Ingénierie Système) b46ca50536 Use correctly the after directory
2015-03-06 15:47:40 +01:00

25 lines
735 B
VimL

" from https://github.com/vim-ruby/vim-ruby/wiki/VimRubySupport
if !exists( "*RubyEndToken" )
function RubyEndToken()
let current_line = getline( '.' )
let braces_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, 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
endif
imap <buffer> <CR> <C-R>=RubyEndToken()<CR>