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.

  • I experience the same behaviour on linux ubuntu, since the last upgrade to 14.10. I dont have any weird windows like settings but the behaviour is the same, also if I prepend somethign else than # it works, but slow, i have to wait liek 3 seconds and if in this time i use arrows - the operation fails, only first line is prepended. Any ideas? – dimovnike Nov 19 '14 at 10:00
  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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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