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

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...

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 ...