I was a vscode user for the longest time, but I was frustrated with the baggage it brought with itself being an electron app. Don't get me wrong, vscode is an excellent piece of software, it's just my personal experience. With that out of the way, after being frustrated with vscode, I decided to give Vim a try, I have attempted to learn vim in the past too but always gave up, but this time I decided to stick to the decision and make the switch. Now, I am not a vim expert so please feel free to correct me if I mess up somewhere.
I will be using neovim instead of vim because I think it's better, although all the instructions and settings are the same for vim apart from some changes, which I will mention if there are any.
From the official website -> Neovim is a fork of the venerable text-editor vim, focused on extensibility and usability. It is not a rewrite but a continuation and extension of Vim. Many clones and derivatives exist, some very clever—but none are Vim. Neovim is built for users who want the good parts of Vim, and more
You can install neovim for your OS, I am using Arch Linux so I will install neovim using
$ sudo pacman -S neovim
You can verify your installation by running the following command.
$ nvim --version
There are plenty of resources available on how to install neovim, if you get stuck google is your friend or reach out to me, I'll love to help.
There are 6 vim modes but mostly you will be working with 3, listed below.
- Normal Mode: This is the default mode vim starts in. While in this mode you can't add or edit the text in your file. This mode is strictly for moving around in your file.
- Insert Mode: As the name suggests, in this mode, you can edit your files.
- Visual Mode: If you want to select some piece of text, this is the mode you do it in.
If all that didn't make sense don't worry I'll explain as we go, I just wanted to introduce the modes before we use them.
To open an existing file or to create a new one type the following.
$ nvim /path/to/file
this will open the file in normal mode, and as I mentioned before you won't be able to edit the file in normal mode.
Exiting vim isn't that hard but it's quite odd when you are coming from a conventional text editor like vscode.
To exit vim while in normal mode press
:q then press
Note: If somehow you got out of normal mode just press
<esc> to go back into normal mode.
Now that you know how to open and close a file in vim let's do something more ie moving around in a file. You can move around in your file using normal arrow keys but vim also provides a better way to move around in your file using the
h j k l keys, where
h is for left,
j for down,
k for up,
l for right, this may seem weird at first but if you think about it, all these keys are in the home row, so they are easy to access than arrow keys. Try to use
h j k l keys to move around in a file in normal mode to get used to it.
To get into insert mode from normal mode press
i key, now you can edit or add text to your file.
Note: Remember you will spend most of the time in normal mode, and to get to normal mode from any mode just press
In this part, we went over the basics of vim, try to practice, and get used to it. In the next part, we will start with some interesting stuff like copying and pasting, the visual mode and we will start configuring vim to our liking.