On 07:59 Sun 21 Oct , tjg wrote:
> I have a file with, e.g., 3 lines :
>
> 121021 Write about Paris with Chris @me &Paris @chris
> 121022 Phone to Inc and Gmbh &Gmbh @me &Inc
> 121029 Talk to Claire about placeholders @me @claire &Foo &Bar
>
> The structure is the same :
>
> - a date
> - some text
> - tags (appended from a Dictionary through a command)
>
> The problem lies with the tags, which are unordered.
>
> I would like to sort the line starting from @ or & patterns and reorder
> (only) these patterns so as to have :
>
> 121021 Write about Paris with Chris @me @chris &Paris
> 121022 Phone to Inc and Gmbh @me &Inc &Gmbh
> 121029 Talk to Claire about placeholders @claire @me &Bar &Foo
>
> (in fact I do not mind what comes first, @ or &)
>
> I tried this solution :
>
> :%call setline('.',join(sort(split(getline('.'),' ')),' '))
>
> but, of course, it sorted the whole line, which was not what I was looking
> for.
>
> I had an idea (?!) :
>
> - split the line on [@&]
> - sort this part of the line separately
> - re-join the 2 lines
>
> The problem is I am not sure it is a good idea, and even if it was, I do not
> know how to do that ...
>
>
>
> --
> View this message in context: http://vim.1045645.n5.nabble.com/How-to-sort-inside-a-line-starting-from-a-precise-pattern-tp5711382.html
> Sent from the Vim - General mailing list archive at Nabble.com.
>
> --
> 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
Hi,
You are on a good track. Note that sort() function has the second
argument {func} which is any sort function. In :help sort() you will
find simple examples of sort functions. You can use matchstr(), to
subtract a part of a string that matches a pattern.
A simpler solution might be to use
:sort {pattern}
see ":help :sort" (I haven't ever used it yet myself).
Best,
Marcin
--
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
Sunday, October 21, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment