Sunday, January 15, 2023

Re: Searching across a range of lines

On Sat, Jan 14, 2023 at 12:53 PM Owajigbanam Ogbuluijah <xigbanam@gmail.com> wrote:
I don't know if you're into completion engines, but coc-java has an "Organize Imports" which does exactly what you're trying to do.

- Igbanam.


Igbanam, I haven't really used completion engines much, to be honest. I had already written an optimize imports script a while ago and was more or less happy with it, but wanted to port it to Vim 9 as an exercise, so thought I would improve it a bit. The original did a lot of in-place manipulation, adding lines, changing import lines in the buffer, moving the cursor around (all with &lazyredraw on, of course), etc. I wanted the new one to read all the import lines into a list, manipulate that list and throw the changed lines down in one single operation. Ideally, also without moving the cursor.

I did get it working with winsaveview() and winrestview(), of course, and I take any added or removed lines into consideration and move the cursor up or down so it remains on the same line in the file as before. I did also come up with a and idea of a wrapper around search() that takes both a start line and (like search() already does, a stop line) and does the search without moving the cursor, but it's cumbersome and I'm not sure it'll be faster than just moving the cursor to the desired start line with winsaveview() and winrestview().

I just figured that if there is a stop line option, there should be a start line option that's not the current cursor position.

Thanks for all your help with this,

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/CANuxnEe8F0spPQ7DpCea%2Bi57U5w3dCQRK9XudTezxLY9KkWfRA%40mail.gmail.com.

No comments:

Post a Comment