#!/bin/bash
# Quick Guide: Text Replacement in Vim
# This script contains examples of text replacement in Vim,
# along with detailed explanations as comments.

# ---------------------------------
# Replace in the Current Line
# ---------------------------------
# To replace all occurrences of a string in the current line, use:
:s/old/new/g
#
# Explanation:
# - `s`: Substitute command.
# - `old`: The text you want to replace.
# - `new`: The replacement text.
# - `g`: Global flag, ensuring all matches in the line are replaced.
#
# Example:
# Replacing all instances of 'board' with 'list' in the current line:
:s/board/list/g

# ---------------------------------
# Replace in the Entire File
# ---------------------------------
# To replace all occurrences of a string throughout the file, use:
:%s/old/new/g
#
# Explanation:
# - `%`: Applies the substitution to the entire file.
# - `s/old/new/`: The substitute command.
# - `g`: Global flag, ensuring all matches are replaced.
#
# Example:
# Replacing all instances of 'board' with 'list' in the entire file:
:%s/board/list/g

# ---------------------------------
# Using Regular Expressions (Regex)
# ---------------------------------
# Vim supports regex in text replacements. For example:
#
# To replace all words starting with "b":
 :%s/\bb\w*/newword/g
#
# Explanation:
# - `\b`: Matches a word boundary.
# - `b`: Matches the character "b".
# - `\w*`: Matches zero or more word characters after "b".
#
# This example replaces any word that starts with "b" with "newword".

# ---------------------------------
# Interactive Replacement
# ---------------------------------
# If you want to confirm each replacement, add the `c` flag:
:%s/old/new/gc
#
# Explanation:
# - `c`: Confirmation flag. Vim will ask for confirmation before
#   replacing each match.

# ---------------------------------
# Examples of Regex in Vim
# ---------------------------------
# Replace all instances of 'board' with 'list' only at the start of a line:
 :%s/^board/list/g
#
# Replace all instances of 'board' with 'list' only at the end of a line:
:%s/board$/list/g
#
# Replace all numbers with 'number':
:%s/\d+/number/g
# ---------------------------------
# Replace from Cursor to End of File
# ---------------------------------
# To replace all occurrences of a string from the current cursor position
# to the end of the file, use:
 :.,$s/old/new/g
#
# Explanation:
# - `.`: Refers to the current line where the cursor is located.
# - `$`: Refers to the last line of the file.
# - `s/old/new/`: The substitute command.
# - `g`: Global flag, ensuring all matches in the selected range are replaced.
#
# Example:
# Replace all instances of 'Modell' with 'Route' from the cursor position
# to the end of the file:
:.,$s/Modell/Route/g
#
# Interactive Confirmation:
# Add the `c` flag to confirm each replacement:
 :.,$s/Modell/Route/gc