On 04/30/2011 10:39 AM, Bee wrote:
On Apr 29, 4:47 pm, "John Beckett"<[email protected]> wrote:
Tim Chase wrote:
let s=substitute(s, '\w\+', '\u\1', 'g')
The above is intended to change each word in s, making the first
letter uppercase and not changing the rest.
The search pattern needs brackets, or the \1 should be replaced.
The following works:
let s=substitute(s, '\w\+', '\u&', 'g')
How would I pass the visual selection to a function with this
substitute?
If you just want to do the replacement over the selected text,
you can do the literal substitute:
:'<,'>s/\%V\w\+\%V/\u&/g
or, if your selection starts/ends in the middle of a word and you
don't want to effect them, you can riff on
:'<,'>s/\%V\<\w\+\>\%V/\u&/g
adding/removing "\<" and "\>" as desired. Any of these can
pretty easily be mapped, e.g.
:vnoremap <f4> :s/\%V\w\+\%V/\u&/g<cr>
If you want to take the selected text, pass it to this
transforming function, and then assign it to a variable without
altering the in-line text, you'll have to grab the selection
either by yanking it to a register, or by using getline() or some
such function (likely in a loop). That gets a bit messy if you
don't yank it to a known register.
-tim
PS: yeah, John caught my "just a little change after I copy &
paste" flub where I previously had used \(...\) to capture things
and \1 referred to them. Sorry if it caused any confusion.
--
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