The :g
command in Vim is a powerful tool for performing actions on lines that match a particular pattern. Below are some practical examples to demonstrate its utility.
Inserting a New Line Below Markdown Headings
Description: Useful in Markdown files to insert a new line below each heading, ensuring that headings and paragraphs are separated.
Deleting Double Empty Lines
Description: Deletes one of each set of double empty lines, reducing them to single empty lines.
Changing Bullet Point Style in Unordered Lists
Description: Changes the bullet point style from -
to *
in unordered lists, which is particularly useful when you want to standardize the list format.
Displaying Lines Containing a Specific Word
Description: Displays line numbers and content for lines containing the word “word.”