If I am to answer the question “What is Vim?”, I would like to quote the official website of Vim,
“Vim is a highly configurable text editor for efficiently creating and changing any kind of text. It is included as “vi” with most UNIX systems and with Apple OS X.”
Vim is a ubiquitous text editor, that is it is available for all operating systems such as Windows, Macintosh and various distributions of Linux. And as you may have guessed (or might not!), Vim is a text editor, that is, it is used to edit text.
Let us see how we can use Vim to create and edit a simple text file. For the demonstration, I will be using Vim on my Windows 10 laptop.
Installing Vim
Vim can be download from their official website (click here for the downloads page).
There is a self-installing executable file for Windows which we shall use. Click on the link to download the setup.
After the file has been downloaded, run the setup. We shall not be changing any settings in the installer as of now. The installer will now install Vim with the default settings.
If you are greeted with an installation finished message, voila! You have successfully installed Vim on Windows.
Starting Vim
Starting Vim is pretty easy. Open up a Command Prompt window and enter “vim”. You will be greeted with the Vim welcome screen.
If you are getting an error that “vim is not recognised as an internal or external command”, you need to add Vim to your Path Variable. This is a handy tutorial on how to do so. You need to mention the path where vim.exe was installed. If you went with the default installation, it should be “C:\Program Files (x86)\Vim\vim82” *where *vim82 can change depending on your Vim version. Restart the Command Prompt terminal and all Vim commands should now work.
Vim has an inbuilt tutorial to get started. Type in “vimtutor” and hit enter to start the tutorial.
We shall now be learning how to create, edit and save a simple text file with Vim.
Working with a Simple Text File
To create a new file, we follow the syntax “vim ”
So to create a new text file, open up your command prompt and navigate to the location where you want your file to be created. Now type “vim helloWorld.txt” and hit enter.
Vim will now create a text file with the name HelloWorld and will open the Vim editor for you to write your content. Vim has many modes in which we can work. Vim will now open in Normal Mode, which is used for simple editing purposes. We need to switch to Insert Mode, where we can insert/edit data in the file. Press “i” to switch to* Insert Mode.*
We will just write in the line “This is a Hello World Text Document.”
Now that we have our file ready, we need to save the contents and quit the editor.
To do this, we first need to switch to Command Line Mode to be able to issue instructions to the editor. Pressing colon (:) in the Normal Mode switches to the Command Line Mode.
To switch from Insert Mode *into *Normal Mode, press “Esc”. Now to move to Command Line Mode, we shall use the colon (:).
To save a file and quit, we use the command “:wq”. And to quit the editor without saving the file, we use “:q!”.
We shall save this file. So type in “:wq” and press enter. And you have successfully created your first text file with Vim!
A Bit about Vim Modes
If you are a bit confused about modes in Vim, don’t worry. Let us summarise what we learnt about modes.
Modes are the various states of Vim editor which have their own purposes. In this demonstration, we learnt about three modes-
- Normal Mode: It is used for navigation around the file and for simple edits. Vim focuses heavily on editing than writing. Since Vim is used a lot by programmers who do more of editing as compared to writing, Vim opens up in the Normal Mode by default.
- Insert Mode: **This mode is used for text editing. Every keystroke in this mode is displayed on the editor screen. To enter into this use, we can use the key “i”. To switch back to Normal Mode, we can use the “Esc**” key.
- Command Line Mode: **This mode is used for operations like saving the file and quitting the editor. Pressing the colon “:**” key in Normal Mode takes us to the Command Line Mode. There are other modes in Vim, which we shall not be discussing at this time. ### Doing More with Vim
- You can learn more about Vim with their inbuilt tutorial. It can be accessed by typing “vimtutor” from your Command Prompt Terminal.
- There is an interactive tutorial to learn Vim. It can be found at VIM Adventures.
- To know more about Vim Modes and how to work with them, there is a handy guide from FreeCodeCamp. That is it. You learnt how to install Vim on Windows, learnt a bit about Modes and created your first text file in Vim. Vim is a very powerful editor and is used by a large number of programmers. Since Vim focuses more on editing than writing, learning Vim would definitely prove to be useful for you. Happy learning!
Top comments (0)