Thursday, November 26, 2009

Re: Delete weird paragraph (or "item" paragraph) (OOPS)

On 27/11/09 05:25, Tony Mechelynck wrote:
> On 28/10/09 11:36, Raúl Núñez de Arenas Coronado wrote:
>>
>> Hi all :)
>>
>> I use Vim to store lists of items, like the one below:
>>
>> - This is a think I should do, or maybe buy
>> - Feed my cat
>> - Tell my cat he is a naughty boy for having chewing up my most
>> expensive headphones without having even considered the possibility of
>> eating a cheaper pair (or none).
>> - Write a message to vim_use to ask how to delete items from lists like
>> this, where some of the items are oneliners but others are clearly
>> not, and may or may not have a final period
>> - More items, this time an oneliner
>> - Stop using computers. NOW!
>>
>> As you can see, the list items are preceded by a dash, and are justified
>> as shown (no problem, Vim already does that). Whenever I modify one of
>> the I can use gqip to reflow that item, and only that item is reflown,
>> not the entire text. That's exactly what I want and works perfectly.
>>
>> The problem is that, sometimes I want to delete, cut or paste an item.
>> Deleting, cutting or pasting one-line items is very easy, just dd or yy
>> and p afterwards. The problem are the multiline items.
>>
>> Right now I just count the number of lines and use<count>dd, etc. But
>> this doesn't scale well and doesn't work if the cursor is in the middle
>> of an item. In those cases I have to go to the beginning of the item,
>> count the number of lines by hand or use visual mode.
>>
>> I wondered if I could use some text-object to perform this action (maybe
>> changing the "dash" for another character) or some more complex command
>> which I could map, whatever, and being able to cut or copy an entire
>> item automatically, without having to go to the start of the item, not
>> having to count lines, etc. I know how to do this using vimscript and a
>> loop, but I wondered if a simpler approach exists.
>>
>> So far, the only solution I've thought of is to add an empty line
>> between items, thus making Vim think they're paragraphs, and use "dap",
>> "yap" and p, but I would like Vim doing what I want without having to
>> adapt my style writing list O:)
>>
>> Thanks a lot :)
>>
>
> Hi Raúl: As you can see, I'm still a month behind. However, have you
> thought of using ranges made of search patterns (for the ":y[ank]" and
> ":d[elete]" commands)? Things like
>
> (starting in the middle of a bulleted item)
> :?^- ?;/^- /-1d
> (note the semicolon to avoid moving the cursor beween both searches)
>
> (or, if it may be followed by a nonindented paragraph)
> :?^- ?;/^\B/-1d

OOPS! Here and everywhere below, it's \S, not \B to match a non-whitespace.

>
> (or, if starting _on_ the dash, not anywhere _after_ it)
> :.,/^\B/-1d
>
> etc.
>
> Of course, this will clobber your search register, but if necessary you
> can save and restore, either in a variable or in another register (but
> _not_ the register used by the delete or yank, of course):
>
> :let svs = @/
> :?^- ?;/^\B/-1y
> :let @/ = svs
>
>
> Best regards,
> Tony.
--
hundred-and-one symptoms of being an internet addict:
206. You religiously respond immediately to e-mail, while ignoring
your growing pile of snail mail.

--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

No comments: