Vim: Request Plugin Addition: vim-abolish by tpope

Created on 9 Mar 2018  Â·  9Comments  Â·  Source: VSCodeVim/Vim

Subvert and the coercion operators are some of my _most_ used features in vim. I can't believe no-one has suggested it yet!?

Abolish may be a difficult thing to emulate, since it adds iabbrev commands to the .vimrc. But, the subvert substitution and the coercion operations are 🔥

areplugin help wanted kinfeature

Most helpful comment

@vegerot Generally because there's only so much we can do in our free time. Pull requests are always welcome.

All 9 comments

I am not super familiar with vimL/vimscript, nor am I familiar with ts. But, I do know C#/F# and js! I am also on a temporary assignment with lots of downtime, so I'll see if I can kludge something together for the extension. I will get started with the contributing guide ;)

@endowdly Did you ever make any progress with this? I would gladly take a stab at it if someone could point me in the right direction. It would be super nice for creating redux actions with something like createStandardAction.

@AlexPattison sadly I did not make major progress.

I did get the mechanics of the vimscript worked out, however I had a hard time figuring out the 'API' of the extension. I ran into a pretty heavy roadblock when I realized that the coerce command would have to operate really similarly to the surround command. The VSCodeVim guys had to do some pretty serious hacking to get that to work in an appreciable way. I was able to get the extension to recognize when we wanted to go into 'coerce' mode, so there's a small victory.

Why don't we have all tpope's plugins in here by default. He's such a legend, and seems like a no-brainer, given all the utility and demand for his plugins

@vegerot Generally because there's only so much we can do in our free time. Pull requests are always welcome.

@vegerot I think there are a couple more issues besides the lack of manpower:

  • tpope wrote amazingly well-crafted plugins, but they are often incredibly complex
  • vimscript cannot be directly ported to TS/JS, so there will always have to be a herculean refactor
  • The other issue is the way vsvim _has_ to tie into the vs code editor--it makes it very difficult to pull off some of the tricks vim can easily do

Because the editor is essentially a web-page, the plugin has to do a couple things: maintain a mode state, action state, and record inputs. There's only so many combinations of states and inputs we can do at any given time, and some vim plugins just can't play together well without removing a standard movement or action. ¯\_(ツ)_/¯

That said, I do think abolish is possible to emulate (closely) in its entirety:

  1. Abolish can write and read from an additional json file that would mimic the vimrc and store the abolish list. The then VsVim could just do a constant text search for those words when in insert mode and change them when they are complete.
  2. Subvert is just an expanded regex find&replace. This is probably the low hanging fruit because it can be placed in the command palette and accessed by the ex command mode like the other commands.
  3. Coerce is tricky as I mentioned before. The easiest way would be to do something like Sneak/EasyMotion does now or utilize difference key modifiers. Coerce would also need a similar hack like how Surround is implemented. This would be the highest difficulty addition.

If I had more time!

About coerce:
So, you see the problem as to get it to work in the keyspace "cr_"?
We can use berknams new remapper to make this quite easy, like so:

@RegisterAction
export class ActionCoerceCamel extends ActionCoerceBase {
  keys = ['<coercecamel>']; // needs to be all lower case
  style: CoerceStyle = 'camel';
}

Plus, users would need one mapping per style (later, it would be nice to be able to auto create these):
nnoremap crm <coercecamel>

I have done a proof of concept here:
https://github.com/sql-koala/Vim/tree/coerceTest/src/actions/plugins

This just replaces the current word by camel (hard coded), but works under "crm" and does not confuse commands "c" or "r".

coerce_crm

I have updated my test. If someone want's to try this, it would "boil down" to implementing the string conversions, like foo_bar -> fooBar.

@RegisterAction
export class ActionCoerceCamel extends ActionCoerceBase {
  keys = ['<coercecamel>']; // needs to be all lower case
  style: CoerceStyle = 'camel';

  public coerceToStyle(text: string): string {
    // todo: implement
    return text + this.style;
  }

Re: Abolish

I found a very good extension that accomplishes abolish-style corrections. Interestingly enough, the author gets it done in the manner I had guessed would be the easiest to do (settings file). If there is a way (through command, like in abolish) to add this to VsVim, then there ya go.

https://github.com/genesy/auto-correct

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gerardmrk picture gerardmrk  Â·  3Comments

triztian picture triztian  Â·  3Comments

typeoneerror picture typeoneerror  Â·  3Comments

st-schneider picture st-schneider  Â·  3Comments

orn688 picture orn688  Â·  3Comments