Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Trying to prepend a # to all lines in a visual block by highlighting, I (shift - i) but only the first line changes (even after hitting esc)

This is the method I've found in a number of places including Vim: Seeing *all* lines change when inserting to a visual block

but it doesnt work for me. Do I need to change a setting or could I be doing something incorrectly?

edit: if it matters, GVIM on windows.

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted
  1. Enter VISUAL-BLOCK mode with <C-v>.
  2. Select all the lines you want to comment.
  3. Type I# to prepend the first line with # then hit <Esc> to exit VISUAL-BLOCK mode and apply your change to all the lines.

I think some people use GVim on Windows with a weird setting that makes its keyboard shortcuts more "Windows-like". If that's your case <C-v> might not work, try <C-q> instead.

  • :help visual-block
  • :help ctrl-v-alternative
  • :help v-b-i

You can obtain the same result without the benefit of a "preview" using the :normal command (:help normal):

  1. Enter VISUAL-LINE mode with <S-v>
  2. Select all the lines you want to comment.
  3. Type :normal I# then hit <CR> to apply your change to all the lines.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.