Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.

Commit 10aba87

Browse files
committed
Expose pluralization as an abolish.vim coercion
1 parent 9063e18 commit 10aba87

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

doc/rails.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,14 @@ most terminals send <M-o> as <Esc>o anyways.
768768
One can also use the <C-E> surrounding in a plain Ruby file to append a bare
769769
"end" on the following line.
770770

771+
*rails-abolish*
772+
Among the many features of |abolish| on vim.org is the ability to change the
773+
inflection of the word under the cursor. For example, one can hit crs to
774+
change from MixedCase to snake_case. This plugin adds two additional
775+
inflections: crl for alternating between the singular and plural, and crt for
776+
altering between tableize and classify. The latter is useful in changing
777+
constructs like BlogPost.all to current_user.blog_posts.all and vice versa.
778+
771779
*rails-cream*
772780
This plugin provides a few additional key bindings if it is running under
773781
Cream, the user friendly editor which uses Vim as a back-end. Ctrl+Enter

plugin/rails.vim

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,42 @@ augroup END
143143

144144
command! -bar -bang -nargs=* -complete=dir Rails :if s:autoload()|call rails#new_app_command(<bang>0,<f-args>)|endif
145145

146+
" }}}1
147+
" abolish.vim support {{{1
148+
149+
function! s:function(name)
150+
return function(substitute(a:name,'^s:',matchstr(expand('<sfile>'), '<SNR>\d\+_'),''))
151+
endfunction
152+
153+
augroup railsPluginAbolish
154+
autocmd!
155+
autocmd VimEnter * call s:abolish_setup()
156+
augroup END
157+
158+
function! s:abolish_setup()
159+
if exists('g:Abolish') && has_key(g:Abolish,'Coercions')
160+
if !has_key(g:Abolish.Coercions,'l')
161+
let g:Abolish.Coercions.l = s:function('s:abolish_l')
162+
endif
163+
if !has_key(g:Abolish.Coercions,'t')
164+
let g:Abolish.Coercions.t = s:function('s:abolish_t')
165+
endif
166+
endif
167+
endfunction
168+
169+
function! s:abolish_l(word)
170+
let singular = rails#singularize(a:word)
171+
return a:word ==? singular ? rails#pluralize(a:word) : singular
172+
endfunction
173+
174+
function! s:abolish_t(word)
175+
if a:word =~# '\u'
176+
return rails#pluralize(rails#underscore(a:word))
177+
else
178+
return rails#singularize(rails#camelize(a:word))
179+
endif
180+
endfunction
181+
146182
" }}}1
147183
" Menus {{{1
148184

0 commit comments

Comments
 (0)