, , , ,

Recently, I had an input file with around 300 lines of data, with one word on each line. I needed to add a prefix, namely ‘stopWords.add(“‘, to each word. I also needed to add a suffix, namely ‘”);’, to the word.

Usually, my go to editor is Notepad++. When I dropped the input file into the editor, I immediately realized that this task was time-consuming. While I am comfortable with using simple regular expressions, I did not know how to do the prefix-suffix thing using Notepad++.

For this purpose, I opened gVim – the GNU version of Vim/vi (also available on Windows).

In gVim, this was a trivial task. I used a substitution operation twice. to add the prefix, I used the ‘%s/^/stopWords.add(“/g’ command. To add the suffix, I used the ‘%s/$/”);/g’ command. The task was done in a jiffy.

Side note: Actually this account is not correct in the true sense. Initially, I started using the copy-paste operation in Notepad++ and continued for a dozon lines or so. Then I realized what a tedious task it was. But as I had started, I did not move to gVim. After adding the prefix, I moved all data to gVim and added the suffix.

Note: ‘vi’ is pronounced as ‘vee eye’ and not as ‘six’.