Site logo

Workflow Example 10/15/19

I was given a task at work: Find all occurrences of a list of parameters in all of the company's projects.

First, I gathered all of the relevant parameters to a single list:

Here comes the fun part - to search for any occurrence of any of these in all of company's projects, let's first convert this list to a valid regex:

(sdkVersion|gdprString|mediaId)

We can now use rg to find this pattern in all of the files in all of the projects. A quick wc -l in projects directory shows us we're dealing with thirty different projects. I quickly cded to the projects directory, and ran the following:

REGEX='(sdkVersion|gdprString|mediaId)'

rg -l $REGEX

The -l flag only lists the filenames containing the match, not the line itself. This will be useful in a moment. Now, we can use rg's output as vim's input in the following manner:

nvim `rg -l $REGEX`

After running the above, we're inside neovim with all of the results open as buffers! Here we use FZF's excellent :Lines command to search in all open buffers. I opened an empty split, and started documenting all of the results. The workflow is using the following mapping:

nmap ,ss :exe "Lines " . expand('<cword>')<CR>

This mapping searches in all of the open buffers for the currently selected word. This way I can go through just 50~ files and note the uses quickly by using the following mapping:

nmap ,cl :let @\\\\\\\\*=expand("%:p")<CR>

This copies the current file's fullpath to the clipboard so I can place it in the empty buffer I'm currently noting the results in. This way, it took me more time to write this description than to actually find the uses, and finish the task.

None of this would be possible without Vim, a terminal, and good software. I have never experienced such a tight integration to a set of powerful tools. I truly feel like my Exobrain is coming along nicely, just now, after nearly seven years of learning and unlearning, exploring and carefully tweaking my work environment.