How to capitalize the first letter of each word?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

How to capitalize the first letter of each word?

Peng Yu
Hi,

I need to capitalize the first letter of each word within a visual
block. Is there a quick way to do it vim? Thanks.

--
Regards,
Peng

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: How to capitalize the first letter of each word?

Tim Chase
On 2014-02-08 08:53, Peng Yu wrote:
> I need to capitalize the first letter of each word within a visual
> block. Is there a quick way to do it vim? Thanks.

You might try

  :'<,'>s/\%V\<./\u&/g

which could be easily mapped if you do it frequently.

-tim



--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: How to capitalize the first letter of each word?

Peng Yu
>> I need to capitalize the first letter of each word within a visual
>> block. Is there a quick way to do it vim? Thanks.
>
> You might try
>
>   :'<,'>s/\%V\<./\u&/g
>
> which could be easily mapped if you do it frequently.

I'm not ':help \u' and ':help &' give me the correct help pages. Do
mind where to find help for them? Thanks.


--
Regards,
Peng

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: How to capitalize the first letter of each word?

Tim Chase
On 2014-02-08 09:10, Peng Yu wrote:
> >> I need to capitalize the first letter of each word within a
> >> visual block. Is there a quick way to do it vim? Thanks.  
> >
> > You might try
> >
> >   :'<,'>s/\%V\<./\u&/g
>
> I'm not ':help \u' and ':help &' give me the correct help pages. Do
> mind where to find help for them? Thanks.

  :help s/\&
  :help s/\u

Strangely, the help-target ":help s/\U" (upper-case "U") takes you to
the same place as ":help s/\&" does rather than to the help on \U (at
least in 7.3.547 which is stock on Debian Stable).  Fortunately
they're in the same block, but it looks like a bug in the
help-tagging.

-tim





--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: How to capitalize the first letter of each word?

Peng Yu
> Strangely, the help-target ":help s/\U" (upper-case "U") takes you to
> the same place as ":help s/\&" does rather than to the help on \U (at
> least in 7.3.547 which is stock on Debian Stable).  Fortunately
> they're in the same block, but it looks like a bug in the
> help-tagging.

I have vim 7.4 and have the same problems.

':help s/\&' brings me to *s/\~*.
':help s/\U' brings me to *s/\&*.

--
Regards,
Peng

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Bee
Reply | Threaded
Open this post in threaded view
|

Re: How to capitalize the first letter of each word?

Bee
In reply to this post by Tim Chase
On Saturday, February 8, 2014 7:06:51 AM UTC-8, Tim Chase wrote:
> On 2014-02-08 08:53, Peng Yu wrote:
> > I need to capitalize the first letter of each word within a visual
> > block. Is there a quick way to do it vim? Thanks.
> You might try
>   :'<,'>s/\%V\<./\u&/g
> which could be easily mapped if you do it frequently.

I have been using:

" Titlecase A Line Or Selection
vmap \<F6> :s/\%V\<./\u&/ge<cr>
nmap \<F6> V\<F6>
imap \<F6> <C-O>\<F6>

I have incsearch set and would like to turn off highlighting after the search. I have a mapping to do this manually:

" manually disable search highlight
nmap <silent> <F4> :nohlsearch<cr>
imap <F4> <C-O><F4>
vmap <F4> <esc><F4>gv

I tried to combine the search replace with nohl but it did not work:

vmap \<F6> :s/\%V\<./\u&/ge<cr> | :nohlsearch

Is there a way to do this?

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Bug in :help parsing (was Re: How to capitalize the first letter of each word?)

Tim Chase
In reply to this post by Peng Yu
On 2014-02-08 09:45, Peng Yu wrote:

> > Strangely, the help-target ":help s/\U" (upper-case "U") takes
> > you to the same place as ":help s/\&" does rather than to the
> > help on \U (at least in 7.3.547 which is stock on Debian
> > Stable).  Fortunately they're in the same block, but it looks
> > like a bug in the help-tagging.
>
> I have vim 7.4 and have the same problems.
>
> ':help s/\&' brings me to *s/\~*.
> ':help s/\U' brings me to *s/\&*.

Additionally, issuing any of

  :help s/\1
  :help s/\2
  :help s/\9

gives me an

  E65: Illegal back reference

but then proceeds to go to the correct help target.  Issuing

  :help s/\~

gives me

  E33: No previous substitute regular expression
  E149: Sorry, no help for s/\~

despite such a help-target in the aforementioned section.

I seem to recall Bram looking into this a while back and fixing it,
but it seems to have returned.

-tim




--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: How to capitalize the first letter of each word?

Jan Christoph Ebersbach
In reply to this post by Tim Chase
Hi,

Thanks for pointing out the very elegant solution of using :s to uppercase every first character.  I created a plugin some time ago that would work for all scenarios except visual-block mode.  Thanks to your answer, I was able to complete it.  The result can be downloaded here:  https://raw.github.com/jceb/vimrc/master/plugin/capitalize.vim

Cheers,

Jan Christoph

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Bee
Reply | Threaded
Open this post in threaded view
|

Re: How to capitalize the first letter of each word?

Bee
In reply to this post by Bee
On Saturday, February 8, 2014 9:57:26 AM UTC-8, Bee wrote:

> On Saturday, February 8, 2014 7:06:51 AM UTC-8, Tim Chase wrote:
> > On 2014-02-08 08:53, Peng Yu wrote:
> > > I need to capitalize the first letter of each word within a visual
> > > block. Is there a quick way to do it vim? Thanks.
> > You might try
> >   :'<,'>s/\%V\<./\u&/g
> > which could be easily mapped if you do it frequently.
>
> I have been using:
>
> " Titlecase A Line Or Selection
> vmap \<F6> :s/\%V\<./\u&/ge<cr>
> nmap \<F6> V\<F6>
> imap \<F6> <C-O>\<F6>
>
> I have incsearch set and would like to turn off highlighting after the search. I have a mapping to do this manually:
>
> " manually disable search highlight
> nmap <silent> <F4> :nohlsearch<cr>
> imap <F4> <C-O><F4>
> vmap <F4> <esc><F4>gv
>
> I tried to combine the search replace with nohl but it did not work:
>
> vmap \<F6> :s/\%V\<./\u&/ge<cr> | :nohlsearch
>
> Is there a way to do this?

Thank you for this thread...

I decided to try other options,
such as changing only lowercase letters:

vmap \<F6> :s/\%V\<\l/\u&/ge<cr>

When the substitute is complete,
there are no longer any lowercase letters and
therefor no highlighting!

Also this seems to be useless:
imap \<F6> <C-O>\<F6>

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.