Hacker News new | ask | show | jobs
Ask HN: What would it take to rewrite Vim?
6 points by hunnypot 4234 days ago
(Yes, I'm crazy, I know.)

So, I'm somewhat okay at programming, with an early-intermediate level of proficiency in Python and C++ by now.

I'd like to know what it would take to rewrite Vim from scratch, with the long term goals of adding in all the sweet Emacs stuff (like integrated scripting and the like) as well as things like an integrated package manager etc.

What things would I need to teach myself? Bear in mind that I do not have much real programming "experience" (as in, I've only written <5K LoC stuff, no real "applications" of even comparable scale).

I am aware of NeoVim, please don't simply point me to it :) Think of this as a stupid personal project, if you will (although I do plan to put this on GitHub and am open to collaboration if it gains any momentum). It doesn't need to be compatible with Vim at all.

8 comments

> what it would take to rewrite Vim from scratch

Time, mainly. Computers these days are fast enough, and have enough storage space that writing Vim will be mostly straight forwards.

The first thing to do, as is for all software, is to make a spec and a roadmap. The doesn't have to be anything too serious, hell, you don't even have to write it out if you don't want to - this is your project after all. (But writing thing down is highly recommended.)

Your spec and roadmap, whether just a notion in your head, or a multi-page written out document with pictures and graphs, should talk about every single feature you want, then break those down into milestones and then break those down into smaller and smaller steps, until they're small enough that you can just start coding (or start googling for the right library)

> What things would I need to teach myself?

Well, you say you know Python and C++. Both are valid choices to write HunnypotVim in; it's your project, so pick one or the other (or a combination of both if you're feeling masochistic). Whatever you chose, you'll need to teach yourself various libraries and their API for your chosen language.

Next, you'll have to decide if you want to make a terminal program, or if you'd rather write a GVim style GUI editor. If you chose a terminal program, you'll need to learn ncurses; a GUI program will need a GUI toolkit, such as QT. Ncurses will have the 'getch' single-character input reader that you'll need in order to reimplement Vim.

You'll also need to learn how to parse command line arguments and file IO.

I'd probably start with a trivial command line argument parser, then move onto basic fileIO before starting in on the ncurses frontend development. Implement normal mode, then hjkl movement keys, finish up with a basic insert mode, and you've got your basic Vim clone!

Additional features left as an exercise for the reader ;)

My email's in my profile if you'd like to discuss this further.

Good luck, and happy coding!

I was thinking of writing the core in C++ (or even Haskell - I just realised that I haven't even considered it!) and using Python as the main scripting language, sorta like it is in Blender.
Why not just contribute to Yi[0]? Yi has seen a lot of development activity lately, and I'm sure your contributions would be welcome.

0: https://github.com/yi-editor/yi

Ooh, ooh, real Haskell!

Thanks a ton, although I might still go ahead with my original plan.

Did you mean Qt?

QT == QuickTime

See bim ("bad imitation of vim") in toaruos

https://github.com/klange/toaruos/blob/strawberry-dev/usersp...

mentioned in these comments in HN a few days ago:

https://news.ycombinator.com/item?id=8566217

I've always wished that other editors would have a full featured vim mode. Either something like RStudio/eclipse using a real vim instead of a few key bindings or a more modern editor like atom.io with a complete vi implementation. Just a thought.

Good luck with your project.

IntelliJ and all its relatives (PyCharm, WebStorm, PHPStorm, etc) have a plugin called "IdeaVim" which fits pretty well with all the usual Vim muscle memory while giving you the toolset of a rich IDE.
Start with a set of Cucumber features that describe all basic Vim like interactions, and declare it as a standard.
software architecture is a bitch, so reading about the book open source software architecture could give you good ideas.

To be more specific decoupling the rendering, from the commands, from the inputs, from the external processes would go a long way.

And some reactive programming model would likely works.

Perhaps start with looking at something less baroque than vim, like the original vi or nvi.
I've actually been working on this. Feel free to get in touch (email in profile).
If I were to rewrite vim I would want to avoid C/C++ and all their warts. A Rust text-editor with guaranteed memory safety would be cool.
Your OS is written in C/C++. When you know what you are doing, these languages are not harmful.
Yeah, and every third boot my display manager segfaults :P

I know it's possible to write good systems software in C/C++, I just think writing in Rust is a marked improvement.