← Back to posts

Journey to VIM (again)

I've first learnt about VIM and seen its power back in 2015, when my teammate at that time showed me a video of someone using VIM. At that time, I was amazed by the speed of this black magic of editing and wanted to try it out, then quickly gave up as I had a hard time doing anything (including the famous exit). It also looked alien to me without the familiar buttons, file explorer, menu items, etc. I was using IntelliJ family at that time and was quite content with what I could do with it. Despite being relatively proficient in IntelliJ IDEs, I've always wanted to get really good at VIM at the back of my mind.

Recently, I've been again inspired and embarked on (yet) another endeavor of moving to VIM (well, Neovim specifically in this case). There are more resources now available online compared with 2015 to help you with transition, which I will list down below. This time, I think it might eventually mount to something, as I have been using Neovim (or VIM bindings in IntelliJ / VSCode) in my work and personal projects for one month now exclusively and the muscle memories have started to grow on me.

So why do I decide to try again? Well, that's mainly because I wanted to get really good at one of the fundamental tasks I do everyday - text editing. Everytime I touch my mouse to scroll, I feel like my editing flow is broken for a little bit. I suppose this is the same reason why people learn all the shortcuts in their IDE.

What makes using VIM difficult

I think the fundamental reason why it is difficult is of two parts:

  • The commands (moving cursor, switching mode, etc.) is unintuitive that requires quite a bit of practice
  • There are a lot of other things that come out of the box in other IDEs which are usually misssing, such as auto completion, syntax highlighting, file explorer, etc.

Overview of my Neovim setup

Firstly, I decided to use Neovim instead of plain VIM. Although there is nothing wrong with VIM itself, I just can't wrap my head around the VIM script syntax. Lua, on the other hand, is much more palatable. It's easier when I open init.lua to add a new plugin.

Secondly, I have tried both Lunarvim and Astrovim, and found both quite sensible. I've ended up using Astrovim simply because I've managed to get it working on my company laptop.

With Astrovim in place, you're good to go with quite a bit of features out of the box. Those are the essential parts of a good working IDE. Astrovim Screenshot

Anatomy of an IDE

LSP

LSP stands for Language Server Protocol. This is what an editor uses to understand your code. It can then highlight the keywords, variables, function names differently, and provide auto-completion. It can also understand symbol definitions so when you Cmd/Ctrl+click, it knows how to jump to definitions. In addition, because it understand your code well, it can perform powerful refactoring functions. Astrovim comes with Mason that allows you to easily install LSPs for different languages.

File Explorer

Another standard fe of an IDE is its file explorer, which allows you to move / delete / create a file / folder. To make it clear, this is a separate piece of work from editing text. Astrovim uses neo-tree for this. It's powerful with buffer and git integration, but I found that it takes a little learning of its commands to use effectively. The most important command is ?, which shows you all other commands. It's a separate window so make sure you only press ? when that window is focused.

Shortcut Keys

I think one of the reasons why IntelliJ family work well is because the standardization of its shortcut keys. I can run tests wiht Shift+F10, rename with Shift+F6 and delete a line with Cmd/Ctrl+Y across them all. Nothing to re-learn. That's why I port over IntelliJ shortcuts on my VSCode to minimize changes. I use this plugin to help me. In Astrovim, one particularly useful shortcut key is j followed by k quickly, to exit (equivilant of ESC key). This is very handy when eidting text because reaching out to ESC is a bit unnatural, as it forces you to move your fingers away. Most other shortcut keys are actually part of various plugins in Astrovim.

Plugins

One thing that attracts me more towards VSCode from IntelliJ family (when I'm not doing Java / Kotlin, it's hard to beat IntelliJ on these) is its ecosystem of plugins. There are just so many of them, if you can think of a need, there's probably one there already. In VIM world, there are also enormous amount of plugins. Astrovim uses Packer to manage plugins.

Other neat things that you get from Astrovim

  • Press space to show a list of possible commands. E.g. space f f to find files, equivilant of Cmd+Shift+N in IntelliJ.
  • Press g to show a list of (LSP I think?) commands. E.g. g d to go to definition of symbol under cursor, equivalent of Cmd+B in IntelliJ.
  • Shift+H/L to move between tabs.
  • Ctrl+H/L to move between windows.
  • <F7> to bring up terminal.

Resources

The following resources have greatly helped me. So many thanks to the authors!

Alright, that's it. Hope it's helpful to you if you want to embark on your own journey to VIM!

HomeBlogContactGithubReading