Skip to main content

Posts

Showing posts from June, 2017

An introduction to Vim macros

Vim is my favourite text editor, because it is minimalist while also being insanely configurable. While I may describe my ideal Vim setup sometime in the future, I do want to share some tips and tricks that make Vim so damn efficient for certain tasks. Today, I shall focus on macros.Here’s the key idea to keep in mind when discussing about Vim. Vim is not just an editor, it is a text manipulation program. Inserting text is just one of the many tasks that Vim can accomplish. A macro is a small Vim program that the user can record in order to make text editing more efficient.Consider a simple use case. Let’s say that I have a CSV file that looks like thisNew York,NY,USA Seattle,WA,USA Mumbai,MH,India Let’s say that I want to add another column at the beginning of each line that is sequentially numbered, like so1,New York,NY,USA 2,Seattle,WA,USA 3,Mumbai,MH,India I could go down each line and manually add each column, but there’s a better way. The solution is to program a Vim macro that …