Vim 8 interface |
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
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
Post a Comment