Commenting Multiple Lines
Steps:
1. Open the File: Open the file you wish to edit in vi/vim. You can do this by entering the following command in your terminal, replacing ‘filename’ with the name of your file.
vi filename
2. Navigate to the beginning of the block: Use the vi movement commands or arrow keys to position the cursor at the start of the lines you like to comment.
3. Enter Visual mode: Press ‘Shift + V‘ (uppercase V). This mode enables you to select multiple lines of text. Use arrow keys to select the lines you want to comment.
4. Commenting the lines: In Visual mode, enter command-line mode by pressing ‘:’ (colon). Now, type ‘s/^/#’ and press Enter. This command employs regular expressions to prepend a ‘#’ character to the beginning of each selected line.
5. After successfully commenting the lines, press ‘Esc’ to exit Visual mode. If you wish to save your changes and quit, type ‘:wq’ and press ‘Enter’.
Contact Us