Loading ...
Sorry, an error occurred while loading the content.
 

How to capitalize the first letter of each word?

Expand Messages
  • 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
    Message 1 of 9 , Feb 8, 2014
      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 vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Tim Chase
      ... You might try ... which could be easily mapped if you do it frequently. -tim -- -- You received this message from the vim_use maillist. Do not top-post!
      Message 2 of 9 , Feb 8, 2014
        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 vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • Peng Yu
        ... 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 3 of 9 , Feb 8, 2014
          >> 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 vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • Tim Chase
          ... 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
          Message 4 of 9 , Feb 8, 2014
            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 vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
          • Peng Yu
            ... 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 5 of 9 , Feb 8, 2014
              > 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 vim_use+unsubscribe@....
              For more options, visit https://groups.google.com/groups/opt_out.
            • Bee
              ... I have been using: Titlecase A Line Or Selection vmap :s/ %V nmap V imap I have incsearch set and would
              Message 6 of 9 , Feb 8, 2014
                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 vim_use+unsubscribe@....
                For more options, visit https://groups.google.com/groups/opt_out.
              • Tim Chase
                ... Additionally, issuing any of ... gives me an E65: Illegal back reference but then proceeds to go to the correct help target. Issuing ... gives me E33: No
                Message 7 of 9 , Feb 8, 2014
                  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 vim_use+unsubscribe@....
                  For more options, visit https://groups.google.com/groups/opt_out.
                • Jan Christoph Ebersbach
                  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
                  Message 8 of 9 , Feb 8, 2014
                    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 vim_use+unsubscribe@....
                    For more options, visit https://groups.google.com/groups/opt_out.
                  • Bee
                    ... Thank you for this thread... I decided to try other options, such as changing only lowercase letters: vmap :s/ %V When the substitute
                    Message 9 of 9 , Feb 8, 2014
                      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 vim_use+unsubscribe@....
                      For more options, visit https://groups.google.com/groups/opt_out.
                    Your message has been successfully submitted and would be delivered to recipients shortly.