
Vim.js – JavaScript port of Vim - DrinkWater
http://coolwanglu.github.io/vim.js/experimental/vim.html
======
brotchie
Nice, I had a crack at doing this a while back using emscripten, but couldn't
get around that Vim's input handling is blocking.

Looks like coolwanglu has found a way around this by hacking some kind of
async transformation into emscripten. I haven't looked at his code, but I
suspect he specially handles known blocking libc calls. My guess is some how
storing the set of stack frames when a blocking function is called so that the
stack can be unwound to let the js engine continue.

Good stuff.

~~~
coolwanglu
Hi, this could be what you need :)
[https://github.com/kripken/emscripten/wiki/Asyncify](https://github.com/kripken/emscripten/wiki/Asyncify)

------
Tyr42
Wow, it's a full vim. I was expecting to find things it couldn't do, but I ran
out of things to try. Great work.

It did take a little longer than vim to load, but I guess that's expected.

~~~
markus2012
It did not work well in Chrome: 36.0.1985.49 beta C-f, C-b didn't even work.

I then gave it a shot in Firefox nightly and it seemed to work really well.
This brings me joy.

I don't like to edit forms/documents on the web; it's a constant struggle
against my muscle memory. Vim.js could be the start of something that could
change that. Well done!

~~~
Sephr
Chrome 36 beta came out _half a year ago_. It's unreasonable to expect web
developers to support very old versions of a browser that silently auto-
updates. Most popular frameworks and libraries, such as jQuery (see
[https://jquery.com/browser-support/](https://jquery.com/browser-support/)),
only officially support the latest stable Chrome and one version prior.

~~~
e12e
Right. So it eas pretty new in July, then?

[https://github.com/coolwanglu/vim.js/commits/master](https://github.com/coolwanglu/vim.js/commits/master)

------
jqm
This is very cool. Enjoyed playing around w/ it. Nice job.

But one thing (for whatever it's worth) what makes vim super useful (to me
anyway) is the plugins and my vimrc with custom key bindings.

(edit) On second look, it appears you can modify vimrc. Very nice.

------
prasoon2211
Can someone please explain how this is different from CodeMirror vim mode? I
am an emacs user and know only the basic vim commands and so, I cannot tell if
there is something fundamentally different between the two implementations.

~~~
brotchie
This is the vim C code compiled into Javascript. Not simply an implementation
of vim behavour, but _the actual vim source code_ compiled and running in the
browser.

------
jamesbrennan
This is great - my favourite part is that this works: `:!alert("Hello!")`

------
dang
[https://news.ycombinator.com/item?id=6899072](https://news.ycombinator.com/item?id=6899072)

------
ludamad
Very nice. It first struck me as just a curiousity but honestly I would
consider using a browser plugin like this that let me edit web forms with
something like this, picking up my local ~/.vimrc. That or for the various
interactive code editing tools like ipython.

~~~
farresito
Vimperator for Firefox lets you edit forms with gvim.

~~~
icebraining
And if you don't want the full power of Vimperator, you can get that feature
with It's All Text! [https://addons.mozilla.org/en-us/firefox/addon/its-all-
text/](https://addons.mozilla.org/en-us/firefox/addon/its-all-text/)

------
Theodores
...er, don't wish to sound negative, this crashed on me. 8Gb RAM Ubuntu box
with Chrome - normally a stable computer that doesn't do things like 'swap'. I
might try it again on my ChromeOS box, but, right now, that is as far as I
got.

~~~
jonawesomegreen
Worked fine for me. Firefox, OSX.

------
bananaoomarang
Although expected, it is a little clunky/slow to use. Fun to play around with
nonetheless, but I wonder whether an Emscripten port of Neovim would be a
little sprightlier.

~~~
teacup50
Why would a port of a more unstable Vim with hacky IPC-based plugin mechanism
be "sprightlier"?

Dropping support for operating systems and reformatting the code doesn't make
it run faster.

~~~
ehsanu1
There is some focus on performance in Neovim (just ctrl-f for it here:
[https://github.com/neovim/neovim/wiki/Progress](https://github.com/neovim/neovim/wiki/Progress)).

But more importantly, all IO is being ported to libuv, from the blocking calls
that are currently being done. This obviously fits Javascript's IO model much
better, as you don't have to fake an event loop in Javascript as this port is
apparently doing - you just use the event loop the JS implementation provides.
After that's done, I'd expect Neovim to work more smoothly as a JS port.

------
italophil
This is really interesting. Perhaps this would allow for vim on ChromeOS
without messing with the linux images (crouton) or the like.

~~~
yathern
Just a tip - if you'd like to use vim on ChromeOS - look into Caret. Its a
nice code and text editor like Notepad++, and it has a vim-mode. Its been a
while since I've used it, and I don't think it's very extensible, but its
something.

~~~
rcarmo
You probably want to look into Zed instead. I found it to be the best editor I
could run on an unmodified Chromebook.

~~~
RadioactiveMan
Zed[1] is probably the best editor on Windows, OSX, and Linux too. I hate to
go back to editors where I have to save, manage what tabs are open, and
clutter the workspace with toolbars and buttons.

[1] [http://zedapp.org/](http://zedapp.org/)

------
waitingkuo
How can I do the pageDown and pageUp in my Mac? I often use ctrl-B and ctrl-F
in the terminal. But it doesn't work here

~~~
ericwood
Fn + up/down arrows

------
UUMMUU
This is awesome. I've tried other attempts in the past but none were as smooth
as this was. Great work!

------
bayesianhorse
I can't wait to integrate this into IPython Notebook...

~~~
bayesianhorse
On further thought that might not be such a good idea because of the nature of
emscripten.

------
make3
cool. am I the only one who gets weirdly blurry text though? win8.1 latest
chrome

~~~
v413
Chrome 39 on Windows 7, when scrolling the text gets blurry. On Chrome 41
Canary though things work well and fast.

------
stray8
Some way to save the file?

~~~
Sir_Cmpwn
It's a crappy hack, but paste this into your JavaScript console:

    
    
        function exportFile(path) { var b = new Blob([FS.readFile(path).buffer], {'type': 'text/plain'}); var u = URL.createObjectURL(b); window.location.href = u; }
    

And then you can run this to export files:

    
    
        exportFile("/usr/local/share/vim/vimrc");

------
vasuadari
Brilliant work!!

------
Ecco
Sorry for the negative tone, but what's the achievement? Emscripten has been
out for a while now...

~~~
_delirium
A straightforward compile of vim using emscripten doesn't work, because the
I/O just doesn't work right (blocking I/O, for one thing). Emscripten works
"out of the box" mostly on computation-heavy rather than interaction-heavy
code.

~~~
Ecco
Thanks, that makes sense ! Don't know why this got down voted BTW, it was a
legitimate question.

~~~
reitanqild
Didn't downvote you but since you seem to wonder about the downvotes I think
they came because you jumped in in a negative way (and was wrong). I'd say
that the downvotes were kind of justified here, - I want HN to be positive to
creators unless they are wrong/evil.

