How to do repetitive tasks in vi?

A general technique that we know is pressing the dot key. But it quickly becomes inapplicable, if one wants to apply a set of tasks repeatedly.

For that, we have the recording feature. When we want to record, press q followed by any symbol in the alphabet or a digit. All the actions will be recorded in a buffer which can be referred to by this symbol. Once the tasks are done, press q again to stop recording. Now we are ready for replaying the tasks. To replay the task, place the cursor at the corresponding position (this can also be recorded and can save you time and energy). Press @<symbol> to replay that set of tasks. If we have to choose one among a set of tasks to do in the current situation, then give the appropriate symbol (of course, you must have recorded that set of tasks with that symbol as its reference). In this way, you can do a set of tasks very easily. Pressing @@ would repeat the last task.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s