Friday, January 13, 2023

Re: Searching across a range of lines


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 &lazyredraw, 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+unsubscribe@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.

No comments:

Post a Comment