tags:

views:

155

answers:

2

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.

+5  A: 

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

Greg Hewgill
+4  A: 

I would recommend going straight to using the NERDcommenter plugin. It comments/uncomments correctly based on the language of the source file and in the way you wanted.

Just install it the "normal" way, i.e. put into ~/.vim/plugin and then you can use V to select a few lines and just press ,cc to comment the whole region and ,cu to uncomment the whole region.

Sam