Tuesday, April 26, 2011

Re: Title Case Selection Only?

On Tue, April 26, 2011 5:17 pm, Bee wrote:
> I have a mapping that works great to Title Case A Line:
>
> " Title Case A Line "? only selection
> vnoremap <F6> :s/\<\(\w\)\(\w*\)\>/\u\1\L\2/ge<cr>
> nmap <F6> V<F6>
> imap <F6> <Esc><F6>i
>
> There is one problem, sometimes I would like to Title Case only a
> portion of a line but this will still do the whole line.
>
> I also tried it without the "g" but then it only does the first word.
>
> vnoremap <F6> :s/\<\(\w\)\(\w*\)\>/\u\1\L\2/e<cr>

You could use

vnoremap <F6> :s/\<\(\l\)\(\w*\)\>/\u\1\L\2/e<cr>

which will only title case the first found lowercase word.
Repeat pressing F6 to title case more words.

Alternatively, try wrapping the whole search string into \%V
which should make sure, that only all selections inside the visual
selected area will get their first letter upper case. Then you need
to visually select the part, that you want to change and press F6
to have each word inside the visual selection change the case.

regards,
Christian

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: