Vim: Insert comment (#) in visual block mode removes leading tabs and only effects first line of block

Viewed 113

I am trying to comment many lines in vim in my python script using an Insert in Visual Block mode (Ctrl-V, highlight all the lines, Shift-I, type "# ", Esc twice), but when it does this it will remove all the tabs from the first line in the block and only insert the "# " on the first line. It will not effect any of the other lines highlighted. In short, it only effects the first line and incorrectly deletes the tabs of the one line that is effected. Does anyone know why this is and/or what I am doing wrong?

I am aware I can use this command :s/^\(\t*\)/\1# but I would like to do this with Visual Block.

Before:

    if(r.is_redirect == False):
        with open(filename,'wb') as output:
            output.write(r.content)

Ctrl-V, j, j, Shift-I, "# ", Esc, Esc

After:

# if(r.is_redirect == False):
                with open(filename,'wb') as output:
                    output.write(r.content)

EDIT: Add proper indentation on Before code

0 Answers
Related