1

I have just posted a question about "How to search a Dictionary with the contents of a list", and received answers by El Isra, romainl and Zyx which solved the question.

But it occurred to me (in a todo list point of view) that it might be interesting to display the results in a specific way, ie, views by categories (or "labels") created.

The resulting lines were :

Call Tom about the Foo project @Tom &Foo
Complete the summary of the Bar project and send it to Thomas &Bar @Tom
Have Susan send me and Tom her forecasts for the Foo project @Susan @Tom &Foo

Is it possible in Vim to display those results after the lines by category (or "label") this way (separated by blank line) :

Call Tom about the Foo project @Tom &Foo
Complete the summary of the Bar project and send it to Thomas &Bar @Tom
Have Susan send me and Tom her forecasts for the Foo project @Susan @Tom &Foo

@Tom
Call Tom about the Foo project &Foo
Complete the summary of the Bar project and send it to Thomas &Bar
Have Susan send me and Tom her forecasts for the Foo project @Susan &Foo

@Susan
Have Susan send me and Tom her forecasts for the Foo project @Tom &Foo

&Foo
Call Tom about the Foo project @Tom
Have Susan send me and Tom her forecasts for the Foo project @Susan @Tom

&Bar
Complete the summary of the Bar project and send it to Thomas @Tom

In fact, I remembered this was the way ("views") Lotus Agenda proceeded, although in a much more sophisticated way...

4

2 回答 2

1

I don't think you'd actually want those grouped results inserted into the original todo file, but rather have a filtered, separate list. For that, the quickfix list is ideal.

I would write a function that iterates over a passed list of categories, and performs :vimgrepadd commands over your todo list, resulting in the following calls:

:vimgrep /@Tom/ %
:vimgrepadd /@Susan/ %
:vimgrepadd ...

This gets you all occurrences grouped by category in the quickfix list, which you can open via :copen. Now, what's still missing is any segregation of the categories. You could use setqflist() to insert separator lines, but I would probably store the number of quickfix elements after each :vimgrep and then build a custom 'foldexpr' that uses these line numbers to fold each category. It's a bit of implementation effort, but you've asked for something outside the usual realm of text editing.

于 2012-09-28T11:17:26.913 回答
0

Even though it is possible to do this in Vim, I think tasks like these are better done in another programming language for the sake of decoupling: Vim scripts are only meant to be used to enhance some part of the editors functionality. That's for example why Vim doesn't have a built-in sort command (update: it actually does now in Vim 7): because this command does a task that is also useful in combination with other editors/commands.

If you create a set of Python/Perl scripts to do this text processing for you (which are arguably better text-processing languages than Vimscript), it would be easy to combine them with Vim, for example:

:%!python myscript.py

Would send the entire contents of the current buffer to myscript.py and replace the buffer with the results. You could also take a look at :help read!.

于 2012-09-28T09:30:46.007 回答