iota icon indicating copy to clipboard operation
iota copied to clipboard

Add Vim-like modes

Open gchp opened this issue 9 years ago • 9 comments

This is not a Vim clone, however I'd like to implement some lightweight version of Vim's modal editing.

Modes to include:

  • [ ] Normal mode
  • [ ] Insert mode
  • [ ] Visual mode

I'll update this ticket as I go along and spec this out a bit more.

gchp avatar Dec 01 '14 17:12 gchp

Instead of reinventing vim, I would suggest integrating with the neovim project. They've separated vim into a server-client architecture and you can tie your own custom client into the server-side of it to add vim functionality to your editor. Though it's still kinda beta, It already works great and "full" vim emulation could be a nice selling point for the editor ;)

p.s. I don't actually know much about how the API works, I just watch/use the project.

webdesserts avatar Dec 11 '14 17:12 webdesserts

If you're redesigning the editor, it might be a good idea to watch @garybernhardt's talk: https://www.destroyallsoftware.com/talks/a-whole-new-world

Or not.

brookst avatar Dec 12 '14 21:12 brookst

@brookst I actually watched this talk a while back, very interesting!

gchp avatar Jan 07 '15 09:01 gchp

@webdesserts that's interesting, do you know where to find the docs for that API? I had a quick look but couldn't find it.

gchp avatar Jan 07 '15 09:01 gchp

@gchp I think it's under http://neovim.org/doc/user/msgpack_rpc.html#msgpack-rpc. Again, this is all still under development. From what I can tell the plugin portion of msgpack-rpc is solid, and the user interface portion (the part you'd need) is well on it's way. They currently have a test python client set up that you could probably take a look at.

I know they also were looking at the possibility of turning the vim core into a library, but that seems much farther off.

There's more documentation under the "for users" section of the wiki.

For more information passed that I'd ask the developers. There's a lot of them and they're pretty responsive from what I've seen.

webdesserts avatar Jan 08 '15 03:01 webdesserts

Just wanted to make a comment here. If you did decide to rebuild vim-like functionality on your own I just have one request:

If you make a fuzzy finder like in sublime, please make ":" open the fuzzy finder and make write, quit and write & quit editor commands (possibly aliased to "save?") and please please please don't make an "ex-command" line with half the features. Take the good parts of vim but don't try to be vim. Only reason I suggest the write commands is because that's soooo ingrained into most of our finger's it's really hard to relearn (but doable if necessary). Beside the normal vim commands, ctrl + \ for nerdtree and ctrl + (arrow keys) for moving between "panes" are probably the only other shortcuts that are heavily ingrained for me, but do with those what you want.

Some other ideas: take the best of both worlds of a fuzzy-finder and ex-commands. Have a fuzzy finder where some of the commands optionally take parameters. So if you type save into the fuzzy finder it saves the file or prompts you for a name/location if it hasn't been saved yet. Or you could type save(~/file.txt) into the fuzzy finder and skip the prompts. Since it's a fuzzy finder you could abbreviate that as s(~/file.txt) (this is honestly starting to sound a lot like ex-commands again).

Or maybe there's an even better way to do things than a fuzzy finder? Who knows. Looking forward to seeing what you come up with.

webdesserts avatar Apr 07 '15 01:04 webdesserts

This is an interesting blog post about vi and why you should not just think of it as just another 'key bindings/modes' but rather a core philosophy of how things work in an editor:

https://medium.com/@mkozlows/why-atom-cant-replace-vim-433852f4b4d1

I would really like to see a proper vi-like editor written in rust from scratch! Thanks!

jpastuszek avatar May 25 '15 16:05 jpastuszek

I have a bit of a suggestion:

You can implement commands emacs-style: everything is a function (delete, move, etc). Then you can have these commands take motion or text object arguments. For example, diw calls delete(in_word).

An advantage of this approach is that it makes it easy to implement any keybinding style using the same functions. eg

Keybind Command
vim dib delete(in_brackets)
common Ctrl+Backspace delete(back_word)
emacs C-S-backspace cut(a_line)

ellisadigvom avatar May 26 '15 13:05 ellisadigvom

@ellisadigvom As an emacs person myself, I do like the everything is a function model. For iota, we wanted to pursue the composability of vi commands in a (hopefully) more flexible way. That medium post @jpastuszek linked was a big inspiration to me (as someone who hasn't used the vi family very much) when writing the current system.

Right now, we have the "command builder" that lets you assemble text-objects from primitives (word, line, char, and "motion" concepts like forward, backward, <number> etc.) and combine them with actions (delete, insert, etc.). You might be interested in the code for this stuff. The editor keeps feeding keystrokes to the "command builder" object until it has something that can be interpreted sensibly, at which point a "symbolic" command object gets returned for the editor to handle.

Rather than binding keystrokes to entire functions, we bound them to "command partials" which can be any of the concepts mentioned above or an entire command, like the open prompt command.

Whether or not this actually ends up making sense in practice or just collapses into an unmaintainable mess remains to be seen... :P

crespyl avatar May 27 '15 15:05 crespyl