Tuesday, January 6, 2015

Re: How to highlight a number out of order with a script

On 2015-01-06 17:50, Cesar Romani wrote:
> I have a text in which all lines end in numbers, like in a table of
> contents. The numbers are supposed to be in ascending order.
> I'd like to write a script which would highlight the first number
> out of order.

While it's not quite highlighting them, you can mark the lines
somehow. I like to indent them, but you can also prepend/append some
other information to the line.

:g/\d\+/if getline('.')+0 > getline(line('.')+1)+0 | sil! > | endif

For this example, the whole line is just the number. You'd have to
tweak the getline(...) by wrapping it in something that extracts just
the number from whatever format of string your lines contain.

The "sil! >" is what indents the lines in question. Feel free to
modify as you see fit.

-tim


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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: