Code Monkey home page Code Monkey logo

Comments (6)

dbarnett avatar dbarnett commented on May 18, 2024

I would guess an implementation based on search() rather than a :substitute command would have a lot fewer side-effects, if we're not stuck w/ this approach for performance reasons or something. @rburny have we already looked into using search()?

from vim-searchindex.

lacygoill avatar lacygoill commented on May 18, 2024

@dbarnett Yes, initially I had the same idea as you. A while loop invoking search() which increments a counter (with a guard to avoid being stuck in an infinite one). Unfortunately, in my limited testing, it seemed that :substitute was sometimes much faster than search(). Maybe I made a mistake, or maybe I just had bad luck with some particular patterns though.

But if search() can, indeed, be much slower than :substitute, I prefer using the latter, because I value the speed of the plugin more than the lost flags/metacharacters, as I almost never use them.

Also, there are a few workarounds to the possible slowness of search(), including the 4th optional argument {timeout}.

from vim-searchindex.

dbarnett avatar dbarnett commented on May 18, 2024

Alright cool, sounds like you've investigated in way more depth than I have. =)
So it sounds like the best path forward is to add the two improvements you mentioned along with some comments about why search() isn't an option for the benefit of anyone trying to improve it in the future.

from vim-searchindex.

rburny avatar rburny commented on May 18, 2024

Thanks for investigating these!

Indeed, I have used :s command because it is much faster. In contrast, any solution that implements a loop in Vimscript (like search() loop) tends to be slow, especially on large files.

I agree with your assessment - let's fix what we can within the current solution. Pull requests are welcome :)

from vim-searchindex.

liushapku avatar liushapku commented on May 18, 2024

One side effect of silent! execute a:range . 's///en' . gflag is that it changes the last substitute string.

For example:

:s/red/blue
/green  (press enter here invokes <Plug>SearchIndex which sets the last substitute string to ''
:~

Without the plugin, the last :~ will replace green with blue. With the plugin, it will replace green with empty string.

The case can be fixed by changing the above mentioned line to

silent! execute a:range . 's//~/en' . gflag

A PR #20 is created for this.

from vim-searchindex.

liushapku avatar liushapku commented on May 18, 2024

The side effect of changing the last used flags is not addressed.

from vim-searchindex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.