Hi,

Raúl Núñez de Arenas Coronado wrote:
> 
> 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.

I think it only seems to reflow one single item, because you probably
use gqip after every modification of an item. For testing purposes I
copied your example to a freshly started Vim and executed gqip. This
reflowed both the third and the fourth item.

If it did work using dip would have been the answer to your question

> 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.

I don't know too much about text-objects, but you could use this mapping:

  :nnoremap <buffer> dip ?^\s*-?<cr>d/^\(\s*-\|\s*$\)/-1

It searches for the previous dash and deletes lines up to the last line
before the next dash or empty line.

This mapping has a problem if the cursor is on the dash at the start of
an item -- it deletes the previous item. You might want to circumvent
this by prepending a $ to the mapping, i.e.

  :nnoremap <buffer> dip $?^\s*-?<cr>d/^\(\s*-\|\s*$\)/-1

Regards,
Jürgen

-- 
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us.     (Calvin)

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

Reply via email to