
Pure Python Vim clone - efbbbf
https://github.com/jonathanslenders/pyvim
======
amelius
Why not decouple the following things:

\- Core editor (internal representation, etc.)

\- Key bindings (so you could easily create an emacs instead of a vi)

\- Rendering

\- Scripting language (for customized behavior)

Finally, make sure you thoroughly document these building blocks, so others
can create really cool stuff with it. Also, think of possible use-cases when
defining the modules. A smart architecture could allow for a collaborative
editor, for example.

~~~
jonathan_s
Hi, thanks for the suggestions! Actually, the internal representation, is
completely separate from the layout. It's not in another repository, but it's
decoupled.

The key bindings are also separate. Getting emacs bindings is not much more
than changing this line [0]. Only adding the bindings for the window
management and emacs command line is still to be done. (I know that emacs is
actually much more than only its key bindings, but you know what I mean.)

The rendering is also independent. There are two backends: vt100 terminals and
the windows console. (Honesly, my main focus is vt100, but any render back-end
is possible. I think even graphical)

The same for the event loops by the way, it can run on a couple of event
loops. For instance asyncio.

Documentation will follow. prompt-toolkit has already quite a lot of examples,
and there's a lot of documentation in the code itself. But I agree that we
should keep improving.

Cheers!

[0]
[https://github.com/jonathanslenders/pyvim/blob/master/pyvim/...](https://github.com/jonathanslenders/pyvim/blob/master/pyvim/key_bindings.py#L26)

~~~
AnkhMorporkian
I want to compliment you on your code. It's so rare to see clean python code.
I am almost never able to be able to jump into a file in a module and
understand exactly what's happening, but you fucking nailed it. Well done!

~~~
notfoss
I believe he follows pep8 ;)

------
evmar
My thought process upon seeing this:

"Python, huh? Seems like typos in uncommon branches of the code would cause it
to randomly fail at runtime, losing your work!"

"Now evmar, don't be such a internet nay-sayer, plenty of people write
reliable Python code. You just need tests and... yep, there's a tests
directory right there in the repository."

"Let's take a look. ...there's only one test!?"

It looks pretty neat other than that, though.

~~~
pekk
It's interesting that your first thought was to post a troll about how Python
is a bad language.

~~~
evmar
I regret that this post is the top of the page. I failed to anticipate that
people will take any opportunity to have yet another boring static typing
debate.

But to be clear, in my day job I work on an app with 350k lines of Python in
it and the reason I know it mostly works is due to our test coverage. As
someone else mentioned in this thread, a lack of tests should not give you
confidence regardless of the language.

~~~
drivingmenuts
From the project docs

"There is no roadmap. I mostly implement the stuff which I need or interests
me, or which gives me the opportunity to learn."

Pretty much says it all. Seems it was primarily written to satisfy personal
needs, not be the end-all, be-all of professionally written software. It is,
incidentally, potentially interesting to others who might want to learn from
it, or use it, knowing the background.

So, you might cut the guy a break. The requirements for personal projects
aren't the same.

------
marktangotango
Fyi there's a similar project here:

[https://github.com/stefanoborini/vai](https://github.com/stefanoborini/vai)

------
kgadek

      Q: Why Python?
      A: The only alternative would be Haskell, but I still have to learn that.
    

Wow, that would be interesting.

~~~
fadsasda432
Hi, I once tried that, but I ran into problems with lazyness. In particular my
data structure was rather simple (famous gap data structure), but editing
"large" files (>1000LOC) became rather unpleasant (too big input-feedback
latency).

However I managed to build a _very_ basic proof-of-concept editor (no
dependencies) in just a few hundreds lines of code which I could explain, but
until now I was too shy to share it as it did not involve magic abstract
Haskell-foo ... ;)

~~~
codygman
> I was too shy to share it as it did not involve magic abstract Haskell-foo

Please don't be, simple understandable Haskell code is very nice :)

Plus if there is a better way of doing it you get to find that out too.

------
esbio
Here is vai
[https://github.com/stefanoborini/vai](https://github.com/stefanoborini/vai) ,
a similar project I started a year and a half ago.

------
marco2357
There's a Java version of Vim here:
[https://www.mtsystems.ch/#section2](https://www.mtsystems.ch/#section2)

It's an automatic translation of the C version.

Like tomp said 4 hours ago: Like vim, just slower.™

~~~
haches
Could you make it available as a Github repo? Would allow to browse it without
requiring a download.

------
tomp
_Like vim, just slower._ ™

~~~
andybak
From the readme:

Why did I create Pyvim?

There are several reasons.

The main reason is maybe because it was a small step after I created the
Python prompt-toolkit library. That is a library which is actually only a
simply pure Python readline replacement, but with some nice additions like
syntax highlighting and multiline editing. It was never intended to be a
toolkit for full-screen terminal applications, but at some point I realised
that everything we need for an editor was in there and I liked to challenge
its design. So, I started an editor and the first proof of concept was
literally just a few hundred lines of code, but it was already a working
editor.

The creation of pyvim will make sure that we have a solid architecture for
prompt-toolkit, but it also aims to demonstrate the flexibility of the
library. When it makes sense, features of pyvim will move back to prompt-
toolkit, which in turn also results in a better Python REPL. (see ptpython, an
alternative REPL.)

Above all, it is really fun to create an editor.

------
krick
So is it vi clone on vim clone, exactly? I just noticed some usual things are
not working (ZQ, for example), but I don't remember, maybe it's supposed to be
that way in vi.

------
rch
This looks great - very hackable. I think I'd like to try adding support for
HDF5 files via h5py.

------
mkonecny
Was this more of a blackbox re-implementation, or is more of a 1:1 code port?

~~~
jonathan_s
It's a blackbox re-implementation. In Python, things are done different from C
and there are other libraries are available (Pygments for instance). I also
don't want to claim that it is as powerful as Vim is. But it should be stable,
easy to install, and especially usable for Python development.

------
Yadi
This is awesome, I just tested it out :)! It would be cool to have the
possibility creating the extensions in future.

------
chestervonwinch
Tried it on OS X. Everything blinks - as in blink-tag blinks. Not sure what's
going on with that...

~~~
jonathan_s
Can you tell me what terminal application you are using? Does it happen as
well in a new terminal?

~~~
chestervonwinch
default terminal app on osx 10.6. happens in a new terminal.

~~~
avinassh
Is there any reason you are still using 10.6?

~~~
chestervonwinch
old laptop. no $$.

------
rhapsodyv
Is there any vim clone that actually have full support to vimfiles?

~~~
afarrell
Does [https://github.com/neovim/neovim](https://github.com/neovim/neovim) not?

~~~
rhapsodyv
But it isn't a clone.

Every clone I see try to reproduce vim usage, but none really try to run
vimfiles. I think running vimfiles is a must have for a clone to get real
users.

------
andor
This is really nice. Does anybody know whether there's a comparable (real
time, asynchronous, highlighting symbols not lines) syntax checker for neovim?

------
yoanizer
Hello, I have a question, what made you want to start this project? What do
you not like about main branch vim?

------
morekozhambu
awesome !!

Does it work with unicode Indic characters?

~~~
jonathan_s
Yes, it should normally work with all unicode characters. (If not, please file
a bug.)

------
eivarv
Very cool!

