Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to comment in vim while respecting the indent?

Tags:

vim

I'm trying to make a mapping in vim to insert comments (for example, "# " - box with a space) while respecting the indenting. So, instead of commenting like this:

class MyFrame(wx.Frame):   
    def __init__(self, title, pos, size):   
#        wx.Frame.__init__(self, None, -1, title, pos, size)   
#        menuFile = wx.Menu()   

I'd to insert the "# " in the code like this,

class MyFrame(wx.Frame):   
    def __init__(self, title, pos, size):   
        # wx.Frame.__init__(self, None, -1, title, pos, size)   
        # menuFile = wx.Menu()   

therefore respecting the indent (which can be tabs or space).

I was trying to get it to work with vim's 0 (zero) command which gets you to the first character in the line, but have been unable. Please, help. I'd be grateful for all ideas and practical suggestions.

like image 965
Thomas Geritzma Avatar asked Dec 29 '22 21:12

Thomas Geritzma


1 Answers

Try using the ^ command instead of 0. Or, use the I command to insert before the first nonspace character on the line.

like image 146
Greg Hewgill Avatar answered Jan 05 '23 18:01

Greg Hewgill