Giter Site home page Giter Site logo

Implement operator-pending mode about vim-mode HOT 16 CLOSED

atom avatar atom commented on September 14, 2024
Implement operator-pending mode

from vim-mode.

Comments (16)

graywh avatar graywh commented on September 14, 2024

Sounds like Atom needs an operator-pending mode.

from vim-mode.

bashcoder avatar bashcoder commented on September 14, 2024

Yes, that might allow for other vim compatibility fixes such as daw, caw and the like.

from vim-mode.

bashcoder avatar bashcoder commented on September 14, 2024

Another example is ctX, where "X" is the variable character marking the end of the change zone.

from vim-mode.

keyneston avatar keyneston commented on September 14, 2024

In addition there is the tX and fX along with all of its variations: dtX, yfX, etc.

from vim-mode.

stuartmemo avatar stuartmemo commented on September 14, 2024

I'm happy to close this if someone wants to create a new ticket with a better description that incorporates all these things?

from vim-mode.

mcolyer avatar mcolyer commented on September 14, 2024

👍 to the operator pending mode, also feel free to edit the issue description/title. Usually I shy away from editing issue descriptions and titles but I think it's fine in a case like this.

from vim-mode.

jroes avatar jroes commented on September 14, 2024

There is some semblance of operator pending going on with the @complete instance variable in operators.coffee, but I think an operator pending mode might make it more explicit and potentially simplify some code. These are the only operators vim officially considers operators - c, d, y, ~, g~, gu, gU, !, =, gq, g?, >, <, zf, g@ I think operators.coffee has a few outliers that we might be able to move to commands.coffee.

If we ever want to implement those multi-character operators, I think we need to start doing timeout stuff. It would actually be awesome if we had direct support for this in atom. For example, I've always bound jk to Esc, and binding j k in my local keymap causes issues in vim-mode :(.

from vim-mode.

stuartmemo avatar stuartmemo commented on September 14, 2024

Have updated title to "Implement operator-pending mode".

from vim-mode.

mcolyer avatar mcolyer commented on September 14, 2024

@jroes 👍 on a more correct operator pending mode and making things generally more correct.

As for the timeout stuff that's honestly what stopped the progress on these more complex commands. Atom's keybinding infrastructure was never really intended to have multiple separate key presses (ie keypresses are considered independently, not within a state machine). I think we can get it there but it just hasn't been a priority.

from vim-mode.

jroes avatar jroes commented on September 14, 2024

I'm off to a slow start guys, this is a little challenging (but fun!) :)

So far what I've done:

  • I created a TextObject subclass of Motion for storing all of our new text objects, and an InnerWord subclass of TextObject that selects the current word under the cursor like vim's iw
  • I implemented an operator-pending mode that looks pretty much exactly like the other modes.
  • I copied a bunch of keymaps into the operator-pending mode map. This felt like a lot of duplication, maybe there is a better way to handle this.
  • I spent some time trying to see if I needed to make any changes to the meaty part of how the operator stack works. After a lot of toying around, I think I found that we are probably going to need this stack, but the name was confusing me a bit. I renamed several spots from operator to operation to better communicate that this is a stack of operations that are being performed, these operations may be operators, motions, text objects, or something else. The way I'm thinking of opStack is as an internal representation of something like "d2w". I documented this for future code spelunkers. I hope this is in line with the overall project vision.
  • I was able to bind i w on its own in visual-mode with no special help there since i isn't already bound. However, I noticed that in vim you can type iw a bunch of times in visual mode and it'll work like w after the first time. I was going to leave that as a future exercise outside of whatever pull request I make for operator-mode

So I think this is a small toe-dip in the waters. From here we should be able to implement aw and several other things simply because the mode has its own context for key bindings and won't interfere with the other bindings. I still think we are going to hit problems where we'll need timeouts though. Hopefully that gets into Atom sooner or later.

Here's a compare for my current branch: jroes/vim-mode@atom:master...jroes:operator-pending
@mcolyer, everyone - what do you think, does this line up with your thinking? At this point all tests pass, so I could make a PR to stop this from turning into a really really big PR, and then we can all make some successive PRs for various text objects and things that should happen in operator-pending mode.

from vim-mode.

jroes avatar jroes commented on September 14, 2024

Oh, forgot to mention -- I'm actually not putting us into operator-pending mode for every valid operator yet. I thought it would be better to do that one at a time as we need it. Doing it all at once brings with it a ton of test failures that will take some time to dig through.

from vim-mode.

ElDeveloper avatar ElDeveloper commented on September 14, 2024

Just adding a note about vip see #111.

from vim-mode.

jroes avatar jroes commented on September 14, 2024

ping -- anyone have a chance to offer some feedback on my comments above?

from vim-mode.

bhuga avatar bhuga commented on September 14, 2024

@jroes, can you make a pull request out of your branch? That will make it a little easier to talk about.

from vim-mode.

jroes avatar jroes commented on September 14, 2024

Will do @bhuga. It has drifted a bit. I've rebased, but there are some test failures now that I'll have to look through and address.

from vim-mode.

bhuga avatar bhuga commented on September 14, 2024

Added in #152

from vim-mode.

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.