Vim Introduction

Vim Introduction

ยท

3 min read

Table of contents

Now to use neovim or vim we need to have a bash type interface which means we can do it only in any form of linux or any form of mac.

vim was the first editor which helped you write into the files , edit into them and also go out of the files.

to see the vim just go to the terminal and then type in this command

vi

now after going into vim we need to exit out to do our normal terminal duties in order to do that we need to type in this command after pressing esc. So when now you see esc written in the command don't just type esc.

`esc` + :q!

and then press enter and we get out of vim editor. with our terminal looking like this

Modes in vim

There are two modes in vim

  1. Insert mode

  2. Visual mode

when we open vim we have the default mode as the visual mode i.e. we can only view our files in this mode but not edit them so to do that we need to go into insert mode.

for example lets create a file and try to see the insert mode and visual mode

vi yo.txt

Now try to type in something but you can't as it is not still in the insert mode, so to do that press i.

i

Now if you want to get back to the terminal you need to be able to exit vim and now in order to that we need to change from insert mode to visual mode. In order to do so this command needs to be entered but here the catch for this command to work you need to press esc once to go back into visual mode from insert mode.

happens when trying to exit vim when still in insert mode so press esc and proceed with this command

`esc` + q!

the problem with the above command is that it won't be saving your file. So to do that we need to use this command

:wq

and now when I view this file again , I get my stuff which was previously typed on it by me.

Now why are we using the ! symbol repeatedly to exit vim, so the logic behind that is say you have a file that you have made changes into and then when you close the file let's say in a normal text editor it asks you whether you want to save the file or not, so in the same way when we use ! is like save without changes

this is my original file that I am editing but I don't want to save so now let me make some changes into it

and now without the ! lets try to run this

now it shows me whether I want to save this or not.

and now if I want to exit it without any changes then I would need to type this command in the visual mode and doing this will not throw any errors.

:q!

Did you find this article valuable?

Support Sohail by becoming a sponsor. Any amount is appreciated!

ย