15 April 2025
by wpAdmin
0 comments
I think I first started using Vim while I was working as a web developer at Lewisham Hospital in the 2000s. I went to some sort of trade show and saw it used in a demo session. It wasn’t the focus of the demo but I saw how the interface could be useful for the text file editing that made up much of my daily work and I have continued using it since then, gradually building up a repertoire of helpful tricks.
One thing I don’t recall using before this week is scripts. You can take a series of commands you might frequently need to run, bundle them together with some optional logic to test the target material and control the flow of execution and then run them as a batch. I suppose that, in the past, I have normally used Vim on systems where I have access to other CLI tools like sed and awk, which would have been my first port of call for batch editing but I don’t have that on the machine I normally get to use at work at the moment. However, I do regularly copy in data from a spreadsheet which comes in a couple of different but consistent formats and which I have been working on by using a series of typed commands.
I now have a short script, consisting of a series of search and replace commands. A couple of useful tweaks were to define the range as between a couple of marks (I picked x and y, which I haven’t been using for any other purpose) and the e flag to suppress error messages when a string is not found. For example, to remove a string like ‘Tuesday 15 April 2025’, my command is 'x,'ys/^.*day \d\d .* \d\d\d\d//e
. That works within the specified range of lines (x to y) and removes a string pattern than is flexible enough to also cope with ‘Monday 12 May 2025’ but without accidentally swallowing up any other information I am expecting to find. Once the whole script (stored in C:\Users\<myusername>) has run, I am left with a list of appointment times and names, which I can then prepend with the name of the service they have booked into and a shortened date format (eg. ‘Tue 15 Apr 2025’), giving me a clear text list to work from.
It probably took me no more than half an hour from starting my research to the finished script (and a lot of manually typing the same commands) and could save me up to five minutes of tidying each time I use it so I should get the return on investment quite quickly as well as having another Vim skill up my sleeve that I am sure I will find further uses for.