Using code snippets

All we mean by the term code snippets is a prepared code that we can read into our current script. This is especially easy with vim being able to read the contents of other text files during editing:

ESC:r <path-and-filename>

For example, if we need to read the contents of a file called if located in $HOME/snippets, we will use the following key sequences in vim:

ESC:r $HOME/snippets/if

The contents of this file are read into the current document below the current cursor position. In this way, we can make the code snippets as complex as we need and maintain the correct indentations to aide readability and consistency.

So, we will make it our duty to always create a snippets directory in our home directory:

$ mkdir -m ...

Get Mastering Linux Shell Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.