Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 6, 2020 09:11 am GMT

Let's learn Vim - The Basics

Introduction

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.

Installation

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.

What is Neovim ?

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 cleverbut 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 pacman.

$ 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.

Vim Modes

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.

Opening a file

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

vim meme

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 <enter>.

Note: If somehow you got out of normal mode just press <esc> to go back into normal mode.

Moving around in a file

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.

Insert Mode

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 <esc> key.

The End

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.

Follow me on Github and Twitter.


Original Link: https://dev.to/thetinygoat/let-s-learn-vim-the-basics-4i8j

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To