4

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.

1
  • 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, 2014 at 10:00

1 Answer 1

11
  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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .