Tuesday, October 22, 2013

Place a sign on each line between two regexps

Hi

I want to place a sign (:he signs) next to each line between two regexps

Example

Beginning with this file

context 1
context 2
start
line …
line …
end
context 3
context 4
context 5
start
line …
line …
end
context 6

the goal is the following

context 1
context 3
start
>> line …
>> line …
end
context 3
context 4
context 5
start
>> line …
>> line …
end
context 6

Assuming the sign is called Foo, the way to place it at line 123 is

:sign place 1 name=Foo line=123 file=/my/file

My first attempt was something like this:

g:/start/+1;/end/-1 exe 'sign place 1 name='.line('.').' file='.expand('%:p')

But this yielded a E481. Apparently exe doesn't support address ranges.

Next thing I attempted was using macros:
let @q=':sign place 1 name=CIInsert line= =line(".")^M file= =expand("%:p")^M^M'

With this definition, echo @q yields:
:sign place 1 name=Foo line=^R=line(".")^M file=^R=expand("%:p")^M^M
and this produces the desired result when I @q on any line.

Using this in combination with an address range:
g:/start/+1;/end/-1 @q
only puts a sign next to the last line of each region. This suggest I'm misinterpreting the way g://;// works. I also tried with ',' and space between the start and end patters, no difference.

Any idea?

--
--
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/groups/opt_out.

No comments:

Post a Comment