Skip to main content

The learn Vim project - Part 1



Over the course of my programming years, I have come to absolutely love Vim. Vim IMHO, is one of the most efficient, fast, and reliable ways to edit any kind of text whatsoever. Many people won't agree with me, but let's not start the IDE/tool wars right away. 

In my mind, if notepad is an old Nokia phone, and Sublime text is the iPhone, Vim would be the PDA that Spy-Kids had on their wrists. The point I am trying to make is, that Vim takes text editing to a whole new level, by making a "text editing language". So just as you have programming languages for programs, markup languages for markup, you can basically start using a text editing language, while using Vim.


This is going to be a multi-part series, going from the absolute basics to an intermediate level.

Let us get started with the very basics.

1. Modes of operation :

   To edit or create a file with Vim, you need to just give the filename as an argument with Vim. ( vim mytext.txt ). Once you do that, you will realise that you can't directly modify the file, This is because, unlike many other editors Vim has specific modes of operation, and each mode is designed for a specific purpose. The modes are : 

- Command mode ( default ) 
     This mode is designed to allow you to view your text file ( or files ), perform search, and modify it by using specific commands. This mode prevents, editing of the file erroneously, because you need to enter a specific command, before Vim allows you to modify the file

- Editing mode
     This mode is what almost all other text editors, open the text files in. It allows you to add/ delete text, just as you would in a Notepad application ( or any other simple text editor ). You can enter this mode by typing the "i" key when in command mode, and to exit you need to press escape key which will take you back to the command mode

- Visual selection mode
    This is a special mode designed to allow you to visually select text, just as you can do with a mouse on any simple text editor. The difference, here is that you need to use your keyboard, instead of the mouse.
Once a text is selected, you can choose to run any text modification command on the selected section of the text.

2. Basics of movement

   Since you will need to use the keyboard for moving around in the text, it helps to know the basics of movement. 

   - Ups and Downs ( h,j,k,l or Arrow keys ) 
      You can either use h ( left ) , j ( up ), k (down ) and l (right ) for moving between lines of text when in command mode, or you can use the standard arrows keys.

   - Finding text ( /, ? , n and p ) 
      You can use the / key to search any piece of text in the entire document. Just type / in the command mode, followed by the pattern ( regular expressions are supported ), and press enter. To go the next instance of the pattern press n, and to go back to the previous occurrence press : Shift + n. To perform a search in the opposite direction, i.e. back from the current cursor position to the top of document, you can use ? instead of /, and the rest of it remains the same

3. Cut, Copy, Paste ( or Delete, Yank, and Paste )

    In Vim world, delete = cut, yank = copy and paste is just paste. The keys used are d ( delete ), y (yank ) and p ( paste ). This works best along with the visual selection mode. So typically to copy some section of  a sentence and paste it somewhere else, you would : 

     a ) Move the cursor to that position by using arrow keys ( or h,j,k, l )
     b) Start visual selection by pressing v
     c) Select the whole section
     d) Press y to yank ( copy ) this section
     e) Move the cursor to the desired destination
     f) Press p to paste it after the cursor, or ( P : Shift + p ) to paste before the cursor 

The same steps would apply to a delete and paste scenario, where instead of yanking with a y key, you would delete with a d key.

4. Save, Undo and Redo

   Now all the changes done above would mean nothing, if we can't save them. A save operation, is literally a disk write operation ( in most cases ), hence it is called a write in Vim world. The command key to write the changes made to the file is w. To undo a particular change, you can use the u key any number of times, and to redo those changes you can use ( Ctrl + r ) command.

With the above information you can start exploring the vast world of Vim. Let me know if you found this helpful. If you have any suggestions, feedback or any other comments, write them in the comment section below. Also, if you found this helpful, do share it with others who can benefit from this. I'll see you in the next section. 

Comments

Popular posts from this blog

Thoughts and Insights For Impactful Living

Over the course of 23 years 6 months 8 days 8 hours 19 minutes now, on this rocky mass revolving around a gaseous nuclear reaction, I have gone through a lot of experiences in my life. I have been fortunate enough to have been living a 'privileged' life, where food, water, air, security and a place to rest my head were never 'real' concerns in my life. In the beginning of every life, you begin your life by observing the people and activities around you, with the inquisitive nature that we as a human beings have developed. This allows us to gain knowledge and learn from the mistakes of others, without actually having to make those mistakes yourself. This by itself is the single most important factor in the exponential growth that the human society has seen. However, what we don't realize in those moments of learning is that the system is beneficial but not absolute. Yes, it is very valuable that you observe and learn, but it does not have to be the only strategy...

Gratitude vs Ambition : What's the right balance ?

Gratitude and ambition are concepts which every life coach, psychologist, or leadership guru talks about at some point. But all things considered equal, they would probably have a strong natural inclination towards one of these concepts. Is there a conflict between gratitude and ambition, and can this be resolved ? Let's explore : Gratitude  Gratitude can best be explained as "enjoying the view, every step of the way whilst climbing the mountain". It is a simple and often undervalued component of a happy and fulfilling life. The influencers who lean towards gratitude, tend to focus on the benefits of just appreciating each moment of peace, and counting your blessings.  Key idea : 'Live in the moment'  Ambition If gratitude is about enjoying the view, then ambition is about "focusing on what reaching the peak would feel like". Ambitious people, create a strong drive within themselves through their strong desires and visions. They are often the ...