Skip to content

Commit

Permalink
Add "Title Case" coercion method (crt) (#17)
Browse files Browse the repository at this point in the history
Also add other examples to README.
  • Loading branch information
tommcdo authored and tpope committed Mar 10, 2017
1 parent 05c7d31 commit b6a8b49
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ There's also a variant for searching and a variant for grepping.

Want to turn `fooBar` into `foo_bar`? Press `crs` (coerce to
snake\_case). MixedCase (`crm`), camelCase (`crc`), snake\_case
(`crs`), and UPPER\_CASE (`cru`) are all just 3 keystrokes away. These
commands support [repeat.vim](https://github.com/tpope/vim-repeat).
(`crs`), UPPER\_CASE (`cru`), dash-case (`cr-`), dot.case (`cr.`),
space case (`cr<space>`), and Title Case (`crt`) are all just 3
keystrokes away. These commands support
[repeat.vim](https://github.com/tpope/vim-repeat).

## Installation

Expand Down
1 change: 1 addition & 0 deletions doc/abolish.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ characters:
k: kebab-case (not usually reversible; see |abolish-coercion-reversible|)
.: dot.case (not usually reversible; see |abolish-coercion-reversible|)
<space>: space case (not usually reversible; see |abolish-coercion-reversible|)
t: Title Case (not usually reversible; see |abolish-coercion-reversible|)

For example, cru on a lowercase word is a slightly easier to type equivalent
to gUiw.
Expand Down
8 changes: 7 additions & 1 deletion plugin/abolish.vim
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,19 @@ function! s:dotcase(word)
return substitute(s:snakecase(a:word),'_','.','g')
endfunction

function! s:titlecase(word)
return substitute(s:spacecase(a:word), '\(\<\w\)','\=toupper(submatch(1))','g')
endfunction

call extend(Abolish, {
\ 'camelcase': s:function('s:camelcase'),
\ 'mixedcase': s:function('s:mixedcase'),
\ 'snakecase': s:function('s:snakecase'),
\ 'uppercase': s:function('s:uppercase'),
\ 'dashcase': s:function('s:dashcase'),
\ 'dotcase': s:function('s:dotcase'),
\ 'spacecase': s:function('s:spacecase')
\ 'spacecase': s:function('s:spacecase'),
\ 'titlecase': s:function('s:titlecase')
\ }, 'keep')

function! s:create_dictionary(lhs,rhs,opts)
Expand Down Expand Up @@ -569,6 +574,7 @@ call extend(Abolish.Coercions, {
\ 'k': Abolish.dashcase,
\ '.': Abolish.dotcase,
\ ' ': Abolish.spacecase,
\ 't': Abolish.titlecase,
\ "function missing": s:function("s:unknown_coercion")
\}, "keep")

Expand Down

0 comments on commit b6a8b49

Please sign in to comment.