codemirror / dev

Development repository for the CodeMirror editor project
https://codemirror.net/
Other
5.93k stars 376 forks source link

Vim Mode #79

Closed curran closed 2 years ago

curran commented 5 years ago

I'd be interested in a "Vim Mode" plugin for CM6.

I wonder if the old Vim mode could be easily wrapped? My guess is likely not, it would need to be re-implemented using the new CM6 APIs.

I'd be interested in working on such a project, and I thought I'd create an issue here in case others are also interested in this. I do realize this would not be part of "core", it would be a separate package.

masad-frost commented 3 years ago

Just posted a $500 bounty for this issue on https://www.bountysource.com/issues/70939750-vim-mode on behalf of replit.com

@thien-do, if you do the same and put the funding publicly via escrow we might get more interest.

Parity with CM5 is more than enough for me, writing an adapter for CM5 vim plugin is probably our best bet.

nightwing commented 3 years ago

I have a mostly working version of CM5 vim mode that uses an adapter similar to the one in Ace. It passes most of the tests (461pass 195 fail). The main CM5 api features that i did not figure out how to implement yet, are replacements for operation, setBookmark methods, change, cursorAcrivity events, and replacement of getScrollInfo usage in vim itself which seems to be unnecessarily complicated now.

marijnh commented 3 years ago

Listening to cursor activity can be done with an update listener (or view plugin) that ignores updates that don't change the content or selection.

sergeichestakov commented 2 years ago

FYI we have a version that's largely working thanks to @nightwing!

We're maintaining a fork at Replit where you can follow updates and track published versions: https://github.com/replit/codemirror-vim

Give it a try via

# using npm
npm i @replit/codemirror-vim

# or if you prefer yarn
yarn add @replit/codemirror-vim

It's still in beta but we've got most of the bugs ironed out by now and have been using it internally for several weeks. If you do give it a try and run into bugs or discover missing features let us know by opening an issue there!

marijnh commented 2 years ago

Nice! Why the fork, though?

sergeichestakov commented 2 years ago

Good point! That was temporary since @nightwing started on it before we started sponsoring + helping out more seriously. We'll be transferring the repo and consolidating soon.

sergeichestakov commented 2 years ago

Update: we've transferred the repo to our org so https://github.com/replit/codemirror-vim is the official upstream repo! @nightwing will remain the primary maintainer for the time being but @masad-frost and myself will be helping out as well

nicholasbulka commented 2 years ago

Awesome! Can you give some insight into how this is working? It looks like a wrapper around the cm5 vim is that correct? Is the new CM6 API used at all? just curious .. thanks for the hard work.

sergeichestakov commented 2 years ago

yep! it's effectively just a wrapper around the old CM5 Vim plugin!

But yes, ultimately the exported extension needs to conform to the CM6 API but that portion is pretty straightforward. It's just an array of extensions including a simple view plugin handling keydown events and command state, a plugin for style, and a plugin for the vim panel (e.g. what you see after you press :)

marijnh commented 2 years ago

Well, codemirror-vim exists, so I'm going to close this here.