Skip to main content

The learn VIM Project - Part 2

Vim 8 interface


This is a series of blog posts, in which I am trying to share my learnings about using Vim, which I have gathered over the course of 4 years of my software development experience. 

This post is the part 2 in this series, please read the first part before continuing forward 


The core commands and the different modes of Vim, should be clear to you by now. We will now talk about some of the more advanced tools available in the Vim language. Let us begin, with combos.

Action-Modifier-Limit


As discussed in the last post, Vim allows us to use a text modification language to alter the text documents we might have. The language, certainly has words, which correspond to the commands that we learned about the first part. But no language can be complete without having sentences. Sentences, should be combination of the aforementioned words, which convey an independent meaning.

The Action-Modifier-Limit Combo, is one such pattern for building sentences. To make this abstract idea, concrete, here is an example : 

Example : ci"

Now, this combination has :
  • c ( which stands for the change command ), as its action, 
  • i ( which stands for in command ), and 
  • " as the limit character
If we combine the parts, into one whole, this sentence ( or combo ), conveys the following meaning : 

change inside "

This combo, can be used to modify all of the text inside the the double quotes, within the document depending on the location of the cursor. To completely grasp the effectiveness of this pattern, we must know, what "Actions" can be used. So here are some examples of the action commands : 

Actions :

  • d - delete
  • c - change
  • v - visually select
  • p - past over
  • y - yank from or copy

Similarly, the modifier which in our case was in can also take various forms : 

Modifiers :

  • i - inside the limit
  • t - till the limit, starting from current cursor position
  • / - search forward till
  • ? - search backwards till

Lastly, the limit is any character in the text that you may use for reference.

Some examples of what can be done with the above combos, are as follows : 

Combo Examples : 

  • yt" - Yank or copy text from current cursor till next occurrence of "
  • ci' - Change all the text inside the single quotes, with whatever is typed next
  • d/are - Delete all text ( or cut ), till the next occurrence of the word 'are'

Numeric Classifiers 

Each of the action commands mentioned above can also be used with a numeric classifier, as follows :     
    
    {number-of-repetitions}{action}

Numeric classifier Examples : 

  • 4yy - Yank 4 lines from current position
  • 50dd - Delete 50 lines from current position

This adds a programmatic advantage to text editing, as now you can cleverly come up with your own combinations, of commands that suit your particular use case. By no means, is this a complete set of commands or actions, there is a lot more to explore. But all those features are best learnt, by editing files inside Vim. I hope you take the examples, and try them by yourself, because only then you will start to become comfortable in this new language. 

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