
Show HN: Build your own Vim emulation for VS Code - johtela
https://johtela.github.io/vscode-modaledit/docs/.vscode/settings.html
======
city41
This is an interesting approach. I find the popular vim emulation extension
(vscodevim) is a bit buggy and has lots of "uncanny valley" gaps.

At work I use vscodevim, and at home I use vim with TypeScript plugins. Both
approaches have lots of annoyances. Maybe a weekend dedicated to ModalEdit
could give me the experience I'm really after. I'm also excited for Oni Vim 2,
which is a commercial product who's promise is to provide the best of both vim
and VS Code.

~~~
cevn
Have you tried the neovim integration setting? I find that almost everything
works as I would expect it to nowadays.

~~~
__s
That only uses neovim for ex mode. Full integration of neovim requires digging
into less widely used extensions such as
[https://github.com/asvetliakov/vscode-
neovim](https://github.com/asvetliakov/vscode-neovim)

I found vscode macros particularly painful. Slow & where vim optimizes things.
Typing abc^H^Hsdf will seamlessly play out as asdf, but with vscodevim I have
to watch the macro repeat my mistake each time

~~~
ubercow13
I have used this extension a bit and it works great as far as I can tell.
Whereas with the older popular VS Code vim extension, I would get broken
behaviour within minutes of use. And I am not a particularly proficient vim
user, this would have just been navigating, using visual mode a bit,
correcting some stuff.

------
mfontani
Vim's power doesn't come from using single-letter commands to do things but,
rather, in the language-like (action, verb, noun) expressions the whole
ecosystem enables: "daw" to delete a word, "cit" to replace the "inner" part
of a tag and start typing, numbered prefixes to execute an action that number
of times, etc.

See also: [https://stackoverflow.com/questions/1218390/what-is-your-
mos...](https://stackoverflow.com/questions/1218390/what-is-your-most-
productive-shortcut-with-vim) aka "Your problem with Vim is that you don't
grok vi."

~~~
johtela
OP here. I completely agree with that. The goal of ModalEdit is not to emulate
those verb-noun commands. VS Code's commands operate on selections, so it is
very cumbersome to turn them to work in Vim way. Instead, you should try to
mimick something like [Kakoune][1] which is another modal editor that uses the
selection as command target.

I'm sure ModalEdit doesn't tempt any hardcore Vim users to use VS Code. But
there are a lot of VS Code user's who have used Vim and like idea of modal
editing. Having an extension that you can configure from ground up is the
value proposition I was aiming for; not to make a poor man's Vim clone.

[1]: [https://kakoune.org/why-kakoune/why-
kakoune.html](https://kakoune.org/why-kakoune/why-kakoune.html)

~~~
jarpineh
Well, this certainly looks interesting. You mean I could use ModalEdit as a
basis to bringing Kakoune like selection behaviour to VS Code as long as I'm
willing to configure it? I have played with Kak, but Code's extensions are
easier to use and more powerful still. I so very much would like to get the
best of both.

Have you used Kakoune yourself? Is there something that's currently not
feasible with VS Code using ModalEdit? I'm still going through ModalEdit docs
to get an idea of what's possible.

Also, Literate Configuration is a good idea. I don't suppose there's a Jupyter
notebook like editor available where markdown and code parts can be seen
alongside in fully rendered form?

~~~
johtela
I have to admit that I haven't used Kakoune myself. I just like its approach
of taking the good parts of Vim and adapting them to more "mainstream" style
of editing.

Because Kakoune's editing operations are much closer to VS Code than Vim's, I
think you can copy its functionality quite extensively with ModalEdit. The
only limitation is that VS Code itself needs to have the commands to support
these operations. The configuration involves just binding key sequences to the
commands. However, VS Code marketplace has so many command extensions, so I
bet you can find substitutes for most Kakoune features there.

Regarding the literate configuration, there is no Jupyter-style online editor
for it, afaik. I use (of course) VS Code to edit my `settings.json` file. In
the background I run [LiTScript][1] in watch mode to generate the
documentation on the fly. I also use the [Live Server][2] extension to
automatically reload the generated documentation when it has been changed.
With this setup, saving the `settings.json` file causes VS Code to reload the
configuration, LiTScript to generate the updated documentation, and Live
Server to reload it automatically. So, it is almost like Jupyter in the sense
that you see your changes in effect immediately.

[1]:
[https://johtela.github.io/litscript/](https://johtela.github.io/litscript/)
[2]:
[https://marketplace.visualstudio.com/items?itemName=ritwickd...](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer)

~~~
jarpineh
Thank you. I'll be sure to check ModalEdit. Since VS Code is so easy to extend
I guess I'll just have to find what things to copy over from Kak. Since Kak
can be used as a server also ([https://github.com/mawww/kakoune/wiki/JSON-
RPC](https://github.com/mawww/kakoune/wiki/JSON-RPC)) I can send stuff over to
it for more extensive editing.

I'll check the LitScript also. Yours sounds like quite a workable workflow.

------
twohearted
I feel like this is missing the point of Vim a little bit. It's not about
using hjkl instead of arrow keys. It's about progressively learning a vast and
useful language specifically made for editing text efficiently. And then
realizing you can use every single part of that language in a macro. And then
realizing you can use that same language to _orchestrate_ those macros.

------
H1Supreme
Why use VSCode at all then? I've found coc.nvim and language servers to be
every bit as good as VSCode in terms of code completion and definitions.

I'm mostly writing Go, C, Javascript, and HTML/CSS. But, so far it's been
working great. And, I'm a fairly recent convert to vim (neovim).

~~~
aidos
For those that are unaware, it’s literally the same system underneath. Vscode
talks to language servers to do all the work and they’ve architected the
system in such a way that others can talk to them too. Coc.vim provides the
plumbing to do that from vim. It’s a great project. Took me a while to get
things configured properly but it’s been great for doing all my typescript
work.

~~~
samatman
Is anyone aware of an 'opinionated' neovim distribution?

Something like spacemacs or Emacs Live, that takes care of all the
configuration work to give a solid basis out of the box.

I've been dragging my feet on switching everything to nvim because I don't
have 'awhile to get things configured properly' these days.

~~~
clappski
At least with coc.vim it's literally just a case of picking a vim package
manager and using that to install it. Almost no configuration required, apart
from `CocInstall`-ing whatever language servers you want.

------
mmahemoff
It's disappointing to see from comments here that there's no true and
performant Vim integration for VS Code.

It used to be the same thing with Eclipse and JetBrain's IDEs. Whatever Vim
plugins existed were slow and falling into the uncanny valley, where they
lacked support for many features or did things in slightly unexpected ways.

Torn between Vim and effectively Vimless IDEs, I chose to stick to the former
and do what's possible to bring an IDE-like experience via plugins, though you
still miss out on a lot in my experience, and any feature you want in Vim
requires a lot more learning and configuring.

The promise of NeoVim was to provide true and complete Vim behavior in IDEs
via its headless network protocol; but the indication here is it still hasn't
happened.

~~~
yodsanklai
> It's disappointing to see from comments here that there's no true and
> performant Vim integration for VS Code.

I've been using vscodevim daily for almost 2 years, and (for me) it's totally
usable. IMHO, much better experience than trying to turn Vim into an IDE.

~~~
jamesgeck0
Yep. It's not 100% perfect, but it's good enough.

Of course it's also be great if I could figure out why my language server
plugins for Vim cause the entire editor to freeze up for a few seconds
periodically despite running asynchronously, or why my intellisense menu
plugin flickers like crazy every time I pull it up. But the ways in which
VsCodeVim don't work for me are more conducive to getting things done than the
ways Vim doesn't work for me.

------
nobleach
One of the biggest issues with Vim emulation in VSCode is that VSCode has no
concept of text objects. Because of this, things like "change inner word" or
"paste" will always have to delete text character by character and re-type (in
the case of the latter). It's sort of like watching a ghost type. I'm still
very impressed with how well it's all working. Atom has AMAZING Vim emulation,
but its text rendering engine is different. It'll be interesting to see what
the Oni folks come up with.

------
jaimehrubiks
For my specific use case the integration is awesome. I can edit text super
fast with all vim keybindings. I also appreciate having the easy motion plug-
in by default, which I also love. I understand that people who know the depths
of vim may lack features they are used to. But for the majority of us it
really improves our coding experience, and at the same time we don't spend
time struggling to add ide features into vim, because vscode is already a
great ide. So when I start using a new file type it just works or there is a
plug-in for it. Same with debugger, compiling, and so on.

------
iimblack
I’ve really wanted to write a Kakoune style layer for VS Code or even a
Kakoune style editor that works natively on Windows.

~~~
ianjsikes
That would be really interesting to me. I have been eyeing Kakoune for a while
and love the idea but I'm too invested into VS Code to completely switch
editors.

------
bananamerica
Just use Evil and have the best of both worlds.

------
trenchgun
Why not just use Doom Emacs?

------
khokhar88
nice article

