GithubHelp home page GithubHelp logo

Comments (2)

pachiras avatar pachiras commented on June 15, 2024 1

Thank you for your kind reply. I appreciate it.

The command %s/if true; then/if false; then/g is exactly what I do always in the situation like this. And I was tired of typing this every time I needed it. Using your library, which is very helpful !, I just thought it would be nice to switch those flags in a single command.

But, you are right. That kind of functionality could cause other side-effects. We should not change it.
The commands you kindly proposed, by the way, look fit my needs. I will try it.

Thank you very much.

from switch.vim.

AndrewRadev avatar AndrewRadev commented on June 15, 2024

It's an interesting idea, but I have a hard time imagining how it would work, exactly. The plugin looks for the text under the cursor and looks for what pattern the text matches. For instance, for the if true example for bash, it would match \C\<true\>.

What I could do is provide a command that replaces it, and then searches to replace the same pattern throughout the same file. But this would affect every true, not just the if true parts, so if you have any other usage of true (even in strings) it would also change and that might be unexpected.

Additionally, for a change like this, it would be good if the range of the operation was controllable, it's rare to have an action that replaces in the whole file. If I wanted to achieve this, I'd use something like %s/if true; then/if false; then/g. But I can also run this substitution on a limited area by selecting visually the first two blocks for example. With a "global switch", the cursor would have to be positioned on something first and then it would be impossible to select an area to operate on.

Can you describe how you'd imagine this global switch action to work in terms of interface? For now, I feel like this is not a good fit for the plugin, and I'd recommend creating a bash-specific command to do this, like putting these two commands in ftplugin/sh.vim:

command! -buffer -range=% Disable <line1>,<line2>s/if true; then/if false; then/g
command! -buffer -range=% Enable <line1>,<line2>s/if false; then/if true; then/g

from switch.vim.

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.