
Ask HN: What would it take to rewrite Vim? - hunnypot
(Yes, I&#x27;m crazy, I know.)<p>So, I&#x27;m somewhat okay at programming, with an early-intermediate level of proficiency in Python and C++ by now.<p>I&#x27;d like to know what it would take to rewrite Vim <i>from scratch</i>, 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.<p>What things would I need to teach myself? Bear in mind that I do not have much real programming &quot;experience&quot; (as in, I&#x27;ve only written &lt;5K LoC stuff, no real &quot;applications&quot; of even comparable scale).<p>I <i>am</i> aware of NeoVim, please don&#x27;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&#x27;t need to be compatible with Vim at all.
======
fragmede
> 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!

~~~
hunnypot
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.

~~~
codygman
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](https://github.com/yi-editor/yi)

~~~
hunnypot
Ooh, ooh, real Haskell!

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

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

[https://github.com/klange/toaruos/blob/strawberry-
dev/usersp...](https://github.com/klange/toaruos/blob/strawberry-
dev/userspace/extra/bim.c)

mentioned in these comments in HN a few days ago:

[https://news.ycombinator.com/item?id=8566217](https://news.ycombinator.com/item?id=8566217)

------
cheriot
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.

~~~
jzila
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.

------
eterps
Start with a set of Cucumber features that describe all basic Vim like
interactions, and declare it as a standard.

------
LBarret
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.

------
james2vegas
Perhaps start with looking at something less baroque than vim, like the
original vi or nvi.

------
akkartik
I've actually been working on this. Feel free to get in touch (email in
profile).

------
gnusouth
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.

~~~
Artemis2
Your OS is written in C/C++. When you know what you are doing, these languages
are not harmful.

~~~
gnusouth
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.

