Vim – tips and tricks

Record a macro that will delete everything after matching character and repeat it N-times.
In this example we’re going to use ‘=’ as the matching character.

qaf=D⏎q

Where:
‘qa’ – to start recording and save it under ‘a’ buffer
‘f=’ – find ‘=’ character
‘D’ – Delete everything to the EOL
‘⏎’ – press ‘enter’ to go to the beginning of next line
‘q’ – to stop recording the macro

then to repeat the macro N-times, i.e. repeat it 5 times:

5@a

‘5’ – the number of times you’d like to repeat the macro
‘@a’ – play macro recorded under ‘a’ buffer

VIM macro delete everything after matching character and repeat N-times

VIM macro delete everything after matching character and repeat N-times

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s