On 08/07/12 21:50, Pablo Giménez wrote:
> I have a string variable and I want to capitalized it letters.
> I also need to caoitalize only the first letter, so if I have:
> let myStr="example"
> Convert myStr word to: Example
> 
> I have been searhing in the docs and google but no luck about how to do
> this in a VimL scripts.

You might have to give a little more context on how you want this to
work.  If you're just doing it once, and you're at the beginning of
the word, you can use the tilde ("~") to toggle the case of the
initial letter.

For more complex changes, you can use the \l \L \u and \U tokens in
the replacement to do things like

  :%s/"\zs\(\w\)\(\w*\)\ze"/\u\1\L\2/

to force the first letter upper-case and the rest of the word
lower-case (or you can omit the "\L" to leave the rest of the word
with whatever case it was initially.

When you say "capitalize only the first letter", what happens with a
multi-word string, e.g.

  let myStr="this is a string"

Do you want

  let myStr="This is a string"

or

  let myStr="This Is A String"

as your result?  Should they only occur in assignments, or in any
string, and what happens if they occur multiple times on the same line:

  let myVar=some_func("this is", "a string")
  frobniculate("some string")

With a better grasp of your use-cases, one can write a more
generalized solution.

-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

Reply via email to