On learning Vim.
Tags: vim, learning, editors
Published: 2020-04-07 22:57:39

---

We spend a lot of time editing code, even more than we do writing new code. We delete, change, uppercase, replace, search for, copy, move, paste chunks of code all day long and we need to optimise for this.

About December 2019 when I had just mastered (... yeah right) VSCode customization and how to wire up the latest and greatest tooling in the JS world I just felt I needed more so I sought out something more integrated as I felt this was what was missing, one tool to conquer them all and I got myself an evaluation copy of Webstorm. 

I thoroughly enjoyed using Webstorm, it is a very smart tool that anticipates my every need but then I still was not satisfied. I know it makes no sense this had all the bells and whistles I should be in editor Nirvana right now, except I wasn't.

I watch a lot of youtube and one of my go-to guys for a quick session of learning and entertainment is Ryan Florence, that man is a mad genius and I noticed how his editor was working for him, how simple it was and straightforward, my interest was not a little piqued so I thought "well I'd give Vim a real go this time"

So in my usual fashion, I scoured the internet and found tons of video, and text-based content on Vim and I got to work.


---


## Welcome to Vi

The first thing I found was that to learn Vim, I needed to accept it for the weird older gentleman that it is, It is different than every text-editing tool I have ever used on a fundamental level. Most people think their problem with Vim is the terminal, but even in Gvim or even emulation mode for Vs Code or `<insert fancy IntelliJ product/>` they would still have the same fundamental issue. [Vim has a language for text editing and to use Vim you must have at least basic familiarity with the language](http://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim/1220118#1220118) mastery is not required, in fact, [you don't need to unlearn other languages](https://yehudakatz.com/2010/07/29/everyone-who-tried-to-convince-me-to-use-vim-was-wrong/) like the use of a mouse or arrow keys you just have to learn this language also else you would hit a wall with every little thing till your head gives way or your ego does and you install Vs Code again.

---

##What mode are we in?
During the [workshop](https://drive.google.com/open?id=1KBfJK5CUTsAx9zUjPb5Wk8SbBdtMNqTY) I gave about Vim at [Omniswift](https://omniswift.com) my colleagues all asked, "how do I type what you just? It's not responding" and I knew to provide an answer I would have to ask "What mode are you in?" 
One of the first things to come to terms within Vim is the fact that Vim is a Modal editor. This modal editing thing is why among many things it allows us to work with only our keyboard.

The way I see it being able to work without a mouse is an affordance of the editor it's not a requirement in order to make use of the editor and so using your mouse is not inherently taboo,*"Vim don't care about none of that"*.

>DISCLAIMER
>I don't use a mouse with Vim, that's just my choice seeing as I have always favoured keyboard shortcuts over clicking on the UI.

The idea of a Modal editor is kind of like a state machine, the same keys can have a different meaning if at all any in different modes. The editor AFAIK defaults to what is called Normal mode. in this mode, you issue out instructions to the editor, these instructions could be any of the following:
 - Do something with the text under the cursor - * Cut it, go to the next word, find all occurrences of this word, delete it, change it, uppercase it… endless possibilities really.*
 - Do something with the cursor -  *Move it maybe*
 - Open a file
 - Go to another mode - * The one where I get to type stuff maybe (this is what we often want)*
 - Quit this whole thing. -* Shoot! I forgot the -m flag again.*

Now that you know Vim needs to be in a specific mode to do what you expect it to you can go about matching your workflow to Vim modes.
I just wanna type code *(read bugs)* then  Vim has INSERT mode.
Now I wanna delete stuff I need to be in NORMAL mode and issue the right command(s) for this.

---

## OPTIONS are Either Some(fun) or None
If you don't get that joke never mind. My point is to prepare yourself for a plethora of options to do the same thing. If you don't like that it's okay, stick with what works for you and don't let anybody tell you differently. You should know though that when you want to take advantage of Vim you may need to explore more options and their nuanced differences, much more than saved keystrokes, things like repeatability, composability and my favourite - ergonomics. 
The coolest part is knowing that this editor and more specifically it's language allows you to be as awesome as you want to be.

---

## But It must be pretty tho.
We like aesthetically pleasing workplaces and our editor must be an absolute beauty to behold. Fear for nothing Vim can be as pretty as you want - Which is more than I can say for a certain IDE *( fake-cough-Storm)* you just need to know where to look.

---

## I know ... but can it autocomplete tho.

There are lots of cool features that our editors give us and sensible autocomplete shouldn't be too much to ask, well you can have it with Vim too, checkout [coc.nvim](https://github.com/neoclide/coc.nvim)

>This was my scatterbrain attempt to write about Vim without going all `Vyy` `2j` `p` on you. please leave a review if you like this show :)