Skip to content

Instantly share code, notes, and snippets.

@ultim8k
Last active October 18, 2024 09:40
Show Gist options
  • Save ultim8k/d8326a0cd7646356acf0dc3baf8e78ff to your computer and use it in GitHub Desktop.
Save ultim8k/d8326a0cd7646356acf0dc3baf8e78ff to your computer and use it in GitHub Desktop.
(un) comment multiple lines vim

From: http://stackoverflow.com/questions/1676632/whats-a-quick-way-to-comment-uncomment-lines-in-vim

For those tasks I use most of the time block selection.

Put your cursor on the first # character, press Ctrl``V (or Ctrl``Q for gVim), and go down until the last commented line and press x, that will delete all the # characters vertically.

For commenting a block of text is almost the same: First, go to the first line you want to comment, press Ctrl``V, and select until the last line. Second, press Shift``I``#``Esc (then give it a second), and it will insert a # character on all selected lines. For the stripped-down version of vim shipped with debian/ubuntu by default, type : s/^/# in the second step instead.

@aquarios77
Copy link

For me "Ctrl + v" > "Shift + i" > "#" > "Esc" sequence did not work iv VI , but worked in VIM (on the same OEL 8 host)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment