How about:
:g/str_list/let items = sort(copy(split(matchlist(getline('.'),
'"\([^"]*\)"')[1], ' \+'))) | s/"\zs[^"]*\ze"/\=join(items, ' ')
The above should be one line
:g/str_list/ " for all lines containing str_list
let items = " Assign to variable 'items'
sort( " Sort the list
copy( " Work on a copy of the list (:help sort())
split( " Split a string into parts (using delimiter ' \+')
matchlist( " Get a list of matches of a regular expression
getline('.') " Use the current line as the search fodder
'"\([^"]*\)"' " Search for a string of non-" characters inside double quotes
)[1] " Take the first match (everything inside the " ")
, ' \+') " See the split comment above
)) " End of sort/copy
| " THEN:
s/ " Substitute on the current line
"\zs[^"]\ze" " Match everything between the double quotes
\= " Expression replace
join(items, ' ') " Replace with a string comprising the sorted items
Al
2008/11/20 MZ <[EMAIL PROTECTED]>:
>
> suppose I have a few line that goes like this:
> str_list="foo bar man act"
>
> how can I sort all the words within the quote " ... " so that it
> becomes "act bar foo man"? It is okay to eliminate extra whitespace so
> that it ends up with only one space behind each word.
>
> --MZ
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---