Monday, November 1, 2010

Re: delete only the short sentences

On 11/01/10 07:40, Joan Miquel Torres Rigo wrote:
> 2010/11/1 Tim Chase<vim@tim.thechases.com>:
>> :v/\%40c./d
>>
>> ("if there's a character at position 40, don't delete this
>> row; otherwise, delete it")
>
> Then you will also remove rows with 61 to 80 characters.
>
> But the strategy is probably good. (I'm not fully expert with
> vim's regular expressions yet and I don't know the meaning of
> '%' in this context).

Actually, the problem is the reverse -- it fails to delete lines
> 80 characters. The \%40c is an atom that matches at column 40

:help /\%c

so any line that doesn't have a character at position 40 (lines
<40 chars) will be deleted. (note that I don't anchor the
column-position to the end-of-line) I'd usually[1] do this as a
2-pass, taking out those >80 in the 2nd pass:

:v/\%40c./d " delete anything shorter than 40
:g/\%81c./d " delete anything longer than 80

I might have some fence-posting errors in there, so 40 might need
to be 39 or 41 and 81 might also be +/- 1, but the logic still holds.

-tim


[1]
Yes, I've had to do the same thing as the OP on several occasions
with various shorter/longer-than thresholds; usually in
column-delimited files with garbage before/after the actual data.

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

No comments: