[HN Gopher] Show HN: Vim online editor using WebAssembly, storin...
___________________________________________________________________
Show HN: Vim online editor using WebAssembly, storing files using
IndexedDB
Author : hassanahmad
Score : 200 points
Date : 2023-01-05 17:02 UTC (5 hours ago)
(HTM) web link (www.vimonlineeditor.com)
(TXT) w3m dump (www.vimonlineeditor.com)
| miket wrote:
| Much easier to exit than standard vim!
| alberth wrote:
| Why can Vim be compiled to WASM but not VSCode?
| TJSomething wrote:
| Because VSCode relies on garbage collection, but WASM doesn't
| support garbage collection yet. Vim is written in C and manages
| its memory manually.
| tcoff91 wrote:
| why would you compile vscode to wasm when it's basically
| already a web app? you can run vscode in a browser already.
| alberth wrote:
| VSCode can be laggy at times.
|
| WASM would help with that.
| scrollaway wrote:
| Why do you think that? WASM isn't a magical "make it
| faster" button.
| alberth wrote:
| Benchmarks indicate as such:
|
| > Wasm is 1.95-11.71x faster than JavaScript on Firefox
|
| > Wasm is 1.15-1.67x faster than JavaScript on Google
| Chrome
|
| > Wasm is 1.02-1.38x faster than JavaScript on Safari on
|
| https://www.adservio.fr/post/how-fast-and-efficient-is-
| wasm
| anaganisk wrote:
| Your benchmarks are analogous to Toyota on highway 0-60
| 8sec Porche on highway 0-60 3sec But Tell me how they
| perform with load, bumpy terrain, tyre wear. Just because
| something runs faster on WASM doesnt mean u have to use
| it, there are othet things to consider to see if its even
| worth it. Vscode is based on mono and is written on top
| of JS/TS. Why woukd you compile it to something and run
| it on top of WASM, rather than just running it using the
| native browser engine.
| mkl wrote:
| That's all a bit beside the point. VSCode is written in
| TypeScript, and there's no easy way to compile TypeScript
| to Wasm as it is designed to rely on a full JavaScript
| runtime.
| easrng wrote:
| But VS Code is already JavaScript, running it in a WASM-
| based JS interpreter instead of a native JS interpreter
| would just slow things down.
| bastawhiz wrote:
| There's nothing here that says that the project in the
| article is faster than Vim, just that it runs in the
| browser. To answer your original question: VSCode's
| internals _already run_ in the browser, so compiling them
| to WASM for the purposes of portability is moot.
|
| To answer the question that you implied ("why can't vscode
| be compiled to wasm for performance"): vscode is built at
| least in part on dynamic languages. There's no compiler for
| JavaScript (or Python, or Ruby) to WASM, you can only
| compile the interpreter for these languages to WASM and
| then run your code in the compiled interpreter. This would
| be slower than what exists today because it's not replacing
| the traditionally-slow bits with WASM, it's replacing the
| fast, native bits with WASM.
|
| The reason there are no compilers for dynamic languages is
| the same reason you can't compile (the full, canonical)
| JavaScript/Python/etc. to native code: the dynamic nature
| of the language prevents the generation of efficient CPU
| instructions. You'd need to do one of a few things:
|
| 1. Rewrite the dynamic code to not use the features that do
| not compile well to native code. Then write a compiler to
| compile the efficient subset of your language to native
| code. This is hard and bad because why use a dynamic
| language in the first place? You can see examples of this
| in projects like AssemblyScript and LLJS (for Python, see
| RPython).
|
| 2. Compile everything you can to efficient native code,
| then make the dynamic bits use less efficient code that
| does work at runtime that other languages could do at
| compile time. This is AOT compilation, and building an AOT
| compiler is hard. Building an AOT compiler that works well
| for most code is extremely hard. Additionally, you couldn't
| do things like load dynamic code at runtime (e.g.,
| plugins).
|
| 3. Write a compiler that interprets the dynamic code at
| runtime, and dynamically compiles that code to native code
| as it is able to identify bits that can be efficiently run
| on the CPU. This is JIT compilation, and building a JIT
| compiler is hard. Moreover, you can't do JIT compilation in
| WASM because it would require WASM to have an API for this,
| and that seems unlikely right now.
|
| 4. Just use a different, more efficient language.
|
| So to answer your question, "why not compile vscode to wasm
| for performance improvements?" You could, but it wouldn't
| be faster. Or, you'd rewrite it in a different language,
| but then it wouldn't be vscode anymore.
| capableweb wrote:
| That's pretty cool!
|
| Wrote a file to test.js with the following:
| console.log(navigator)
| document.querySelector("#pastebtn").innerText = "PASTE"
|
| And then run it with `:!test.js` and it executes it in the
| current browser context. Editor editing itself :)
| alex_smart wrote:
| That's very Emacs of Vim.
| tomsthumb wrote:
| bang to run a command is from ed. thats pretty core vi
| espadrine wrote:
| I am impressed that it even supports pasting with "*p
| varunkmohan wrote:
| Wow, very smooth to use! Would be extra neat if this could
| support plugins as well.
|
| We're building out a free AI code completion tool, Codeium that
| will support Neovim as an IDE and would love to hook into this as
| well.
| rav wrote:
| It makes me sad every time I try a Vim with a non-zero
| 'scrolloff' setting. Since I started using Vim I have learned to
| use H and L efficiently when navigating, but non-zero 'scrolloff'
| changes where H and L move the cursor to - and somehow non-zero
| 'scrolloff' is now the default in Ubuntu if a user hasn't created
| a vimrc file (even an empty file will do).
|
| Note that this seems to work much better in Chrome than in
| Firefox - when I press Ctrl in Firefox, it activates Visual Block
| mode (so e.g. Ctrl-D, Ctrl-U, Ctrl-O, Ctrl-I won't work).
| pyrolistical wrote:
| Is safari still evicting indexeddb after 7 days?
| https://web.dev/storage-for-the-web/
|
| If so, Indexeddb should only be used to store "unsaved" files for
| safari.
|
| Chrome and Firefox support https://caniuse.com/mdn-
| api_permissions_persistent-storage_p...
|
| But that implies if the user denies persistent storage, then
| indexedb should be again only used to store "unsaved" files
| csdvrx wrote:
| If you are into this, note there's also a JavaScript online Vim:
| https://wang-lu.com/vim.js/emterpreter/vim.html
| avnigo wrote:
| The WASM version does seem considerably more snappy to me.
| b33j0r wrote:
| Guys, I love the topic.
|
| Save me. I'm losing faith in the pursuit. Typed the headline into
| ChatGPT and it gave me every single step.
|
| What the heck are we going to do now?
| b33j0r wrote:
| I'm getting criticized a lot for noticing that the nature of
| our work has changed.
|
| I suggest that we simply converse on the topic, but I guess it
| sounds like BS to people.
|
| Heed my warning, you can get a model of our career to write any
| program you can phrase. I'm telling you, for you.
| alexeldeib wrote:
| ChatGPT is generative word salad with high accuracy. Your
| previous comment was somewhat doom and gloom without
| providing interesting content for discussion -- like the
| conversation, output, and a running example as a peer
| mentioned. There wasn't much interesting to discuss which
| hadn't been said about chatgpt already.
|
| Fwiw, I think it's a force multiplier, not a replacement. It
| requires skill to determine the quality of the output, can
| raise the bar of inexperienced developers by producing output
| more quickly and accurately than they could, empowers
| experienced developers by generating boilerplate faster than
| they can, and can improve learning by providing examples for
| specific use cases.
|
| But when it's wrong, it has no idea. It often answers riddles
| with intuitive but wrong answers. It provides code that
| doesn't compile. Explains answers with logic that is entirely
| wrong. Push it and you'll see.
|
| It's impressive but not apocalyptic. See another highly
| ranked post on the idea of "AGI hard" if you think I'm moving
| goalposts.
| binarymax wrote:
| Did you actually use the source suggested and get it running
| somewhere?
| andirk wrote:
| Am I the only person on earth who uses plain vi?
| cassepipe wrote:
| That's great ! I have been looking for such a quick online vim
| experience for quite some time.
|
| A month ago I did find what I consider to be even better : make
| of any textarea on any page a neovim instance with the firenvim
| extension (thanks to which I am writing this comment _in_ neovim
| _in_ my browser!)
|
| It's not even a vim-like experience, it's literally your
| configured neovim in the browser !
|
| Somehow I haven't managed to get it to the front page (this is
| not my creation but I am a big fan since I have been looking for
| this for so long)
|
| I even get autocompletion and all coding niceties in the little
| code playgrounds that are all the rage in nowadays tutorials
|
| https://github.com/glacambre/firenvim
|
| https://addons.mozilla.org/en-US/firefox/addon/firenvim/
| antonmosich wrote:
| Wow I just looked into that project and it really seems to work
| great. I really struggled a lot when typing longer responses in
| my Browser when trying to input my vim commands, so hopefully
| that will help.
| finnh wrote:
| Ah thank you! I've been using wasavi on Chrome but real-vim may
| be enough to pull me back to Firefox.
| glacambre wrote:
| Firenvim is also available on Chrome (although I do recommend
| using Firefox for browser monoculture avoidance :) ) : https:
| //chrome.google.com/webstore/detail/firenvim/egpjdkipk...
| spurgu wrote:
| Please give your vote here:
| https://connect.mozilla.org/t5/ideas/macos-allow-custom-
| keyb...
|
| If that simple feature gets implemented there'll be at
| least one more FF user in yours truly. :)
| dontchooseanick wrote:
| Does kinda work
|
| Perfect :
|
| * Using :left and V , set ts=4 sts=4 sw=4
|
| * Recording macros with q
|
| * Main vim combos - it's definitely vim
|
| Fails :
|
| * Typing { or } on a MacBook Air under Firefox - don't know which
| of this settings cause the bug. Reproducibly, { does not work
|
| * Replaying a macro containing { or any error
|
| Kudos for the compilation (emscripten ?) and Brace for impact
| (the incoming bugs) :)
| naillo wrote:
| Really cool! Excuse me for my naivete but is there a benefit to
| writing normal JS but then compiling it to wasm? Does that make
| it faster? Was kinda expecting C or some other language when
| viewing through the source on github.
| brrrrrm wrote:
| I believe the vim.wasm is pre-compiled and checked in as a
| "binary." The javascript written is a runtime wrapper
| hpen wrote:
| Yay, it's like vim only shittier!
| frankzander wrote:
| What's the use case for that?
| __MatrixMan__ wrote:
| To see if it's possible.
| codetrotter wrote:
| From the linked page:
|
| > Why use Vim Online Editor?
|
| > 1. Because you love vim.
|
| > 2. Because you don't have access to vim somehow (maybe you're
| on a Chromebook that doesn't allow access to the system)
|
| > 3. Especially if you're on Windows and you still want to use
| vim.
|
| > 4. Because you want a notepad of some sort in the browser,
| and you want to use vim bindings instead of normal notepad.
| codetrotter wrote:
| Point 3 I don't quite understand though. Last time I was
| using Windows, several years ago, I was perfectly able to run
| gVim on it. I can only imagine that with the subsystem for
| Linux and other things that have been added since then,
| surely it has only become easier to run Vim.
|
| Last time I was actively using Windows was in the late WinXP
| / early Win7 era. But I don't see why Win 10 / 11 would make
| running Vim difficult.
|
| I do agree with all of the other points though.
| OkayPhysicist wrote:
| neovim also has windows builds now, daily driver for me.
| dontchooseanick wrote:
| +1
|
| As a heavy vim user, I've literally been using gvim.exe
| every day on Windows for the past decade
|
| https://www.vim.org/download.php#pc
| feklest wrote:
| That is very cool, nice to see vintage editors hosted in a modern
| environment.
|
| What I'd really like to see return is an online version of
| EDIT.COM, and maybe also its host binary QBASIC.EXE, not just for
| the nostalgia but because it was a pretty decent editor for the
| time, it even supported editing binary files if you didn't have a
| hex editor to hand, though you had to use Alt+(numpad) for most
| characters.
___________________________________________________________________
(page generated 2023-01-05 23:00 UTC)