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

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

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

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