Re: Searching across a range of lines

2023-01-13 Thread Salman Halim
On Fri, Jan 13, 2023 at 8:13 PM Tim Chase  wrote:

> On 2023-01-13 16:41, Salman Halim wrote:
> > For example, I want to find a match for 'cat', but only in lines 50 to
> > 100. If my cursor is before line 50 when I start, I can prefix my
> > expression with \%>49 and pass 100 as the stopline, but that doesn't
> > work if my cursor is AFTER line 50 as it starts the match at the cursor
> > location.
> > I don't want to first move my cursor.
>
> While possibly not quite what you're looking for, if I want such, I use
>
>   :50,100g/cat
>
> or, if I want to know which line-numberss:
>
>   :50,100g/cat/#
>
>
> -tim
>

Tim, this doesn't do what I'm trying to do, but the bigger problem is that
:g absolutely moves the cursor, putting it on the last found match.

Thanks very much,

Salman

-- 
-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/CANuxnEcXzUyY%3Db8bEofU1yKQHWqbsOjmCrSKnApc57C9H%3DK3Gg%40mail.gmail.com.


Re: Searching across a range of lines

2023-01-13 Thread Salman Halim
>
>
> I don't know your specific requirements, but not wanting to move
> your cursor should not prevent you from using search().  Just save
> the cursor position, save the window position, move the cursor to
> the start of the search range, and when you're done with the
> searching, restore the window position and the cursor position.
>
> I've done this in a number of plugins and I can't even tell that the
> cursor ever moved.
>
> Regards,
> Gary
>

Thanks, Gary. I've solved it with , winsaveview() and
winrestview(), but I really would prefer to not move the cursor. I'm trying
to write a routine that will remove unused Java imports. My method is to
find the import section of the file, read all the lines in, search each
entry in the file (outside the import region) and remove any not found;
lastly, I put the modified lines back into the buffer, after sorting them
and removing duplicates, also.

That 'search each entry' currently requires me to move the cursor to just
past the import section and then do a search. I would prefer not to move
the cursor to do that as I can do everything else without moving the cursor.

Thanks again,

Salman

-- 
-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/CANuxnEeY%3DzMOKCsDSu8n2RBUJL4wW4ghMySgb-AMNT%2Bma6XukQ%40mail.gmail.com.


Re: Searching across a range of lines

2023-01-13 Thread Tim Chase
On 2023-01-13 16:41, Salman Halim wrote:
> For example, I want to find a match for 'cat', but only in lines 50 to
> 100. If my cursor is before line 50 when I start, I can prefix my
> expression with \%>49 and pass 100 as the stopline, but that doesn't
> work if my cursor is AFTER line 50 as it starts the match at the cursor
> location.
> I don't want to first move my cursor.

While possibly not quite what you're looking for, if I want such, I use

  :50,100g/cat

or, if I want to know which line-numberss:

  :50,100g/cat/#


-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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/Y8IBig8i30NxtWYm%40thechases.com.


Re: Searching across a range of lines

2023-01-13 Thread Gary Johnson
On 2023-01-13, Salman Halim wrote:
> Hello,
> 
> I want to use something like search(), but only across a specific set of 
> lines.
> The problem is that search() always starts at the current cursor line.
> 
> For example, I want to find a match for 'cat', but only in lines 50 to 100. If
> my cursor is before line 50 when I start, I can prefix my expression with 
> \%>49
> and pass 100 as the stopline, but that doesn't work if my cursor is AFTER line
> 50 as it starts the match at the cursor location.
> 
> I don't want to first move my cursor. I'm also hesitant to use getline() to
> grab all the lines, do an indexOf type search and then return the line number
> because that's going to get memory intensive if I have a large file.
> 
> Does anybody have any thoughts on this? I'd appreciate advice.

I don't know your specific requirements, but not wanting to move
your cursor should not prevent you from using search().  Just save
the cursor position, save the window position, move the cursor to
the start of the search range, and when you're done with the
searching, restore the window position and the cursor position.

I've done this in a number of plugins and I can't even tell that the
cursor ever moved.

Regards,
Gary

-- 
-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/20230113221402.GF6446%40phoenix.


Searching across a range of lines

2023-01-13 Thread Salman Halim
Hello,

I want to use something like search(), but only across a specific set of
lines. The problem is that search() always starts at the current cursor
line.

For example, I want to find a match for 'cat', but only in lines 50 to 100.
If my cursor is before line 50 when I start, I can prefix my expression
with \%>49 and pass 100 as the stopline, but that doesn't work if my cursor
is AFTER line 50 as it starts the match at the cursor location.

I don't want to first move my cursor. I'm also hesitant to use getline() to
grab all the lines, do an indexOf type search and then return the line
number because that's going to get memory intensive if I have a large file.

Does anybody have any thoughts on this? I'd appreciate advice.

Thank you very much,

-- 

Salman

I, too, shall something make and glory in the making.

-- 
-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/CANuxnEdmGJyMwFkatS1SpDnaADOc%3D3fVN4zX%2BUMX6deBKAW3dQ%40mail.gmail.com.


Re: [Solved]: Yanking doesn't yank

2023-01-13 Thread arocker


>
> Thanks for that, Gary.
>
> I'm officially an idiot.
> --
> Ottavio Caruso
>

At least you're an honest one. :-)*
Welcome to the Order of the Golden Face-Palm, which I think we all earn at
one time or another. Confession and explanation improves collective
wisdom.

-- 
-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/f69b2f21f6fe775d98137f20e599298c.squirrel%40webmail.vybenetworks.com.