Hacker News new | past | comments | ask | show | jobs | submit login
Vim.js - JavaScript port of Vim (coolwanglu.github.io)
199 points by sebg on Dec 13, 2013 | hide | past | web | favorite | 100 comments

Rule 34 for software: If it exists, there IS a javascript port of it.

That would be Atwood's Law: any application that can be written in JavaScript, will eventually be written in JavaScript.


And tlrobinson's Law (or corollary?): Any submission to Hacker News about a novel JavaScript program will contain a comment referencing Atwood's Law.


What about emacs in Linux in JavaScript? :-)


It would be missing a good editor. Probably not a bad operating system however

All it needs is for someone to implement JavaScript in elisp and the circle would be complete.... :-)



Ejacs is an Ecma-262 compliant JavaScript interpreter written entirely in Emacs Lisp. It should work in GNU Emacs versions 22 and higher.

What about emacs in Linux in JavaScript? :-)



PatientZero's law: Any submission to Hacker News about a novel Java script program containing a reference to Atwood's law will contain a reference to tlrobinson's law.


...authored by tlrobinson?

Even more true now that Emscripten and asm.js exist.

I'm normally unimpressed by applications ported to javascript. However, this actually has me excited. I would love to be able to edit all my Dropbox text files with a web interface. If anyone here works for Dropbox, I beg you to integrate this!

If it's possible to integrate this with BrowserFS, you'd be all set: https://github.com/jvilk/BrowserFS/#browserfs

http://dillinger.io/ you already can

There is also http://stackedit.io

Really cool! It even supported doing things like:

    inoremap jj <Esc>`^
Backspace ended up triggering the browser's back action though. Other than that, this is really nice.

Edit: After looking at the source, this seems to make use of emscripten to reuse Vim's existing source code. This really makes me wonder what other cool things we can bring over to the client side.

… There are still browsers that use backspace for navigation?

(I'm a little surprised by this because I've seen so many complaints about it leading to data loss.)

_I_ use backspace for navigation. What's the alternative? Use a mouse?


On Mac OS X, the standard shortcut is Command-[ instead (and Command-] is Forward).

I generally use three fingers swipe to the left.

As do I. Actually, if I have a mouse, I tend to right click, then hit back, it's the first option.

In general Command-Left/Right-arrow should work as well unless it's been taken out of Safari.

if you use vimium/vimperator/something else you can do shift+H to go backwards, shift+L to go forward.

Which would require me to press two keys instead of one.

Considering we're talking about Vim here, pressing keys should be second nature to you anyway...

yeah but not to move your hand if you're on the homerow

There are still browsers that don't maintain form state across back/forward history?

(I'm a little surprised by this because I thought all browsers used backspace for back)

Chrome and Firefox. Probably IE too.

Not on Linux, where the 'previous page' action is mapped to Alt-left by default. After being initially frustrated, I got really used to Alt-Left for going back.

The reasoning behind it is pretty smart too, because numerous times backspace can result in the loss of data, like when you're filling up a form and you hit backspace outside of a text box.

Indeed, I like the 'alt-left' keyboard shortcut, though I especially like it because it does the same thing in both Chrome and Firefox on both Windows and Linux! Yay for consistency!

No, at least for me (Firefox on Linux) Backspace doesn't do anything special.

The “backspace = back” behavior of Firefox is only enabled by default on Windows. The behavior is controlled by the about:config setting `browser.backspace_action` (http://kb.mozillazine.org/Browser.backspace_action).

It also appears to be enabled by default on Mac OS X.

Ah, thanks. I don't need it anyway :) Alt + Left/Right works fine.

I tried typing some gibberish and one shortcut that seems to be a bit broken for me is yiw diw

Hmm, actually it seems all the motions I tried didn't work :-(


This... Plus Gmail... Man that's fantastic. I have sent an embarrassing number of emails that end with :wq.

Once you try Vim, it's really hard to go back. I also tried using mutt instead of GMail, and while it gets me 90% of the way there, the lack of graphical preview of attachments and things like filters and HelloSign make GMails web interface more useful.

There are browser plugins that let you edit <textarea> elements in your $EDITOR.

I use "It's all text!" in Firefox for this purpose and it works well; the workflow is pretty simple: focus in textarea, hotkey to switch to vim, save & close buffer to switch back to the browser. (not affiliated, just a user).

You do of course lose rich text formatting.

You just made my day, m'am and/or sir.

Anybody know one for Chrome?

I do not... Last time I looked was a couple months ago, and I didn't find anything.

Yep, I constantly have to delete jj at the end of emails. The cool thing about this port is that mapping seems to work. Naturally the first thing I tried was :inoremap jj <esc>, which I don't think works in codemirror + vim plugin.

Who uses :wq when you can use :x?

I save very often using :w. When I want to save and exit my brain is now hard-wired to do :wq. It would probably take a year for me to train myself to use :x, which is arguably just as slow since I have to reach down with my ring finger instead of up. Not saying anyone should switch, just that it would be hard for me to do so.

Who uses :x, when you can ZZ?


Oh man, this even has tabs!

All the three letter motions I tried don't work. Without them this is more vi then vim. caw ci" ca( all don't work.

It is built with the compiler flag: --with-features=tiny.

For Vimium users: don't forget to enter the insert mode in your browser first ;)

This is pretty cool. Backspace not working for me though in Chrome.

Same here, Chrome on Debian.

Backspace and ESC not working, so after I enter a mode I'm stuck in it forever.

did you port ncurses using emscripten? This could enable bringing a large portion of GNU over to the browser as a cloud-based app. Stallman's nightmare, in other words.

It works amazingly well. However don't split windows then use ctrl-w j to switch. The browser captures ctrl-w first and closes the tab. Other ctrl-* combinations don't work probably for similar reasons.

See also http://codemirror.net/demo/vim.html (though that's only the editor component, not a whole vim implementation)

this is not vim, this is some incomplete bindings implementation.

Who wants to make a javascript emacs? you could call it emscriptenmacs..

ymacs (Fabrice Bellards Emacs "clone") is installed in jslinux.

Ymacs is written by Mihai Bazon. It has nothing to do with Bellard. http://www.ymacs.org/

Edit: And it’s _written_ in JS, not ported.

I tried it, and now I'm confused and angry! Seems right to me.

Cool. Now go build NERDTree and Ctrl-P and come back. Then I will use it

You still use those?

I really hope someone will patch it into the IPython notebook (or at least enable the codemirror vim keybindings). If I can find the time to learn some javascript I'll give it a go myself.

nice but `backspace` then I returned to > https://news.ycombinator.com/item?id=6899072

same here, cool idea though.

Can anyone think of a sane way to make this integrate with github?

Thanks! I was trying to get my head around why vim mode wasn't working. This works great.

Given the size of the "compiled" file, i'd say it's a bad idea . A better idea would be whatever js editor with a vim mode, not c code compiled with emscriptem like this one.

Its already been done as a chrome extension


Github is using the Ace editor, which has a VIM mode.

Lots of comments seem to expect some further web integration with various services but this looks like more of a prototype/proof-of-concept using emscripten.

Cool nonetheless.

While this is impressive, I find it surprisingly slow compared to much more demanding applications with bigger code bases compiled via Emscripten. Any ideas why?

Well, I don't know what you mean by slow, but it could be the use of setTimeout() every 10ms to simulate[1] Vim's synchronous busy-wait is affecting responsiveness.

Lu mentioned[2] on vim_dev that it was necessary to write a hack for this portion.

[1] https://github.com/coolwanglu/vim.js/blob/master/web/vim_lib...

[2] https://groups.google.com/forum/#!topic/vim_dev/AQTHbUHijgg

Yeah, I hit this same road-block when trying to port vim to JS and gave up because it didn't seem worth it after that. If only vim ran a regular event loop, it would have been such an easy port, compared to what they had to do here. When figuring out how I could overcome it, I remember reading accounts of KDE developers trying to embed vim into their widgets and failing over and over. In the end, there was a solution to "embed" vim with some special IPC the netbeans IDE developers put into vim, but you had to run vim as a separate process for that to work - which is not possible on the web as it stands today. The numerous synchronous busy-wait loops in vim killed all approaches I had considered, so kudos to these guys for figuring out a way, even if it's slow.

There's an event loop patch on vim_dev being played with. Maybe in the next 12 months we will see some action with that approach or the other "timers" approach submitted (and ignored by Bram) by the floobits devs.

This also does not seem to be compiled with full optimizations, standard emscripten -O2 output looks somewhat different than what is here.

Very slow (unusable) on a MacBook Air 1.4GHz 4GB RAM using Chromium 30.0.1589.0 (215899). I suppose it's the price of using an emscripten port.

OMG you made my day, split window and window navigation, tabbing is all there!!!

Just need we need now is syntax highlighting and color torte :P

Fantastic work!

Waiting for os.js, javascript port of X operating system. And js.js, javascript port of javascript. Javascripteption anyone?

There are already several PC emulators in JS, and there are at least two Javascript interpreters in JS:

This one is Spidermonkey compiled with Emscripten: https://github.com/jterrace/js.js/

And this one is a test-bed for new JS language features (or at least meant to be - don't know how far along it is): https://github.com/mozilla/narcissus

Wow, I can use hjkl to move my cursor !!!

Kinda cool as a demo, but too many vim shortcuts are hijacked by the browser for this to be useful to me.

Very cool! I know code mirror had vim mode but this. This is something way more awesome.

Out of curiosity, any reason why the vim script isn't minified if it is so huge?

Genuinely much more impressive than I was expecting! Well done!

Too slow for me on FF.

Too slow for me on Chrome.

so... what exactly am i supposed to do with no file system?

Fork it and have it save in localStorage, or POST (ajax or <form>) it to your host site for saving.

One idea could be to bundle it with haste[1] or similar.

[1] https://github.com/seejohnrun/haste-server

It seems to have some kind of filesystem. You can write files, there's /dev, /root, /tmp and /usr, and vimrc and color settings.

Not really sure how it all works, I only took a quick look.

Why not Acme.js yet?

fantastic! One issue - I keep hitting is using the backspace key in chrome is mapped to the back button... so it keeps taking me back here..

Totally failed when I tried backward-delete-word.

Ctrl-[ and Ctrl-c don't work :'(

Still good job!

Ctrl-[ seems to work for me

I use Vim for everything, this is great!

Can it take in custom vim rc files?

"ciw" doesn't work.

Hrm ctrl+w dang.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact