This might at some point become a real plugin, right now it's just a little project to learn vimscript.
The idea is to have a set of functions that present similar functionality as ActiveSupport::Inflector and make it easier to go from something like 'some_var' to 'SOME_VAR' or 'SomeVar' to 'some_var', etc.
Because it seemed simple enough for a first approach into vimscript and because available options require either python or ruby.
Probably any plugin manager will work.
With vim-plug:
Plug 'farfanoide/inflector.vim'
With Vundle:
Plugin 'farfanoide/inflector.vim'
With dein:
call dein#add('farfanoide/inflector.vim')
Inflector does not ship with any mappings so in order to use it you have to add
some to your vimrc. To have the plugin create them for you, just set
g:inflector_mapping
, for example:
let g:inflector_mapping = 'gI'
Or if you want, set them manually:
nmap gI <Plug>(Inflect)
vmap gI <Plug>(Inflect)
Done, now you can gI
some text (stands for go Inflect
).
With those mappings you can call the Inflect function in normal mode passing it
a text object or a motion, IE: gIiW
, or gI/searchsomething
. Inflector will
ask you for the type of conversion you want to apply.
The idea behind the plugin is to have a sort of "Text Multiplexer"
which can
translate from any of the recognized patterns to any other, meaning: it should
be the able to go from PascalCase
to CONSTANT
or camelCase
and viceversa.
This is done by having a common representation which currently is based on a
list so SomeText
translates into ['some', 'text']
and from there it's
trivial to convert to any other representation.
Inflection | Alias | Input | Command | Output |
---|---|---|---|---|
Dotify | . |
someTextToWork | gIiw. |
some.text.to.work |
Dasherize | - |
some_text_to_work | gIiw- |
some-text-to-work |
Underscore | _ |
some text to work | gI$_ |
some_text_to_work |
Camelize | c |
Some Text To Work | gI$c |
someTextToWork |
Constantize | C |
some text to work | gI$C |
SOME_TEXT_TO_WORK |
Pascalize | P |
some.text.to.work | gIiWP |
SomeTextToWork |
Titleize | t |
some text to work | gI$t |
Some Text To Work |
Normalize | n |
SOME_TEXT_TO_WORK | gI$n |
some text to work |
Slashify | / |
SOME_TEXT_TO_WORK | gIiw/ |
some/text/to/work |
FreeBallIt | f |
some text to work | gI$f& |
some&text&to&work |
Privatize | p |
some_var | gI$p |
_some_var |
Privatize
is handeled differently, it only check if the text being transformed
already starts with an underscore.
FreeBallIt
allows the user to specify any character to join the separated
words.
So far, tests are ran via Vader, open
inflector.vader and run :Vader
See the LICENSE.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- add repeat support
- add vim help?