VIM – Comment blocks of code

Proved to be quite useful when editing system configuration files (Apache2, etc.). Thanks!

Commenting in blocks of code

Similarly, you may go the reverse direction and comment in blocks of code as follows:

  1. Go to the first line of the block of comments signs you would like to delete: <line>gg
  2. Enable block selection mode: Ctrl+V
  3. Important: Only mark the comment tokens you want to delete, nothing else!
  4. Navigate to the end of the block either with
    • <line>gg or
    • arrow up/down;  j/k
  5. Press d for deletion

(If necessary undo your changes with u)

Leave a Reply