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

The skill of Storytelling

Stories have acted as a mechanism of transferring learned experiences with other human beings within small tribes,since our hunter-gatherer years.  Even before we had written communication mechanisms, such as books, ( or even paper for that matter ), all human tribes were communicating their ideas, through story-telling. It would be a fair assumption to make, that all these stories were generally used by the senior members of a tribe, to educate the young and bright minds, who were just starting their journey as a tribe member. Since, oral communication was the norm, oratory skills must have been the key differentiator, between charming leader, and the other senior members of the tribe. Good storytelling has been the key tool in a leaders toolkit, for as long as human tribes have existed. If you, as a leader, can convey your ideas effectively, and convince the other members to agree on your version of a story, you were a very successful tribe leader. The conv

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

Of Downfalls and Come-backs

The story of failures are often more interesting than successes. You start with a goal in mind. You break it down into multiple smaller goals. You schedule your time, and work diligently towards completing each one of them.  You put all of your heart , mind, soul , time , energy and sacrifice to make this one thing work. Then you put it out in the world. But the world owes you nothing, and that one thing fails. You have dedicated yourself to the results, but still the results elude you. This is failure. Failure sneaks up on you while you are unaware, and now you have to face the consequences. You get "feedback" from others. You ask yourself, how could I let this happen ?  You start seeing yourself get stuck in a loop of reflection and guilt, and it all seems to crumble down. Meanwhile, the world is oblivious to all of this. The birds are singing, flowers are blooming, and the sun completes its cycles. The disconnect between an internal whirlwind, and external calm, is mind-bo