views:

33

answers:

1

I am using gVIM and the tComment plug-in during editing the development.ini file in a Pylons/Python project. The default development.ini file has lines commented out using the hash # symbol which is the standard method of commenting out lines in Python. However, when I try to uncomment lines by using a tComment keyboard shortcut in gVIM, I do not see the # go away. Instead I see a semicolon get added to the beginning of the line.

How do I correct the behavior of tComment so that it adds, or removes, #s instead of adding, or removing, semicolons in Pylons .ini files?

+3  A: 

In the tcomment.vim file in your autoload directory you should find a list like this:

call tcomment#DefineType('aap',              '# %s'             )
call tcomment#DefineType('ada',              '-- %s'            )
call tcomment#DefineType('apache',           '# %s'             )

In there you'll find this line:

call tcomment#DefineType('dosini',           '; %s'             )

Assuming that you don't need to comment windows .ini files too often, you can just change it to this:

call tcomment#DefineType('dosini',           '# %s'             )

Update:

Here's a slightly better option since you don't have to edit anything but your vimrc. Since your vimrc is generally loaded first, any built in filetypes we try and define get redefined by the above file, so let's make our own:

au BufRead,BufNewFile, *.ini   set filetype=pythonini
call tcomment#DefineType('pythonini',           '# %s'             )

We firstly set .ini files to our own filetype, pythonini, then add our own tcomment definition for it.

To keep your vimrc nice and portable, you may want to check whether or not we have tcomment before trying to call it:

if exists('loaded_tcomment')
    au BufRead,BufNewFile, *.ini   set filetype=pythonini
    call tcomment#DefineType('pythonini',           '# %s'             )
endif
Alligator
No I will not have to comment Windows .ini files often. Thanks. Is there another way by calling the DefineType function from the .vimrc file? I heard it was better to do that then change the original tcomment.vim file.
J3M 7OR3
Are you sure that second version from **Update** will work? As vimrc is loaded before any plugins, you won't have `loaded_tcomment` variable defined at that point, you should add something like `runtime plugin/tcomment.vim` before `if exists(...)` in order to get this working.
ZyX
The syntax of the call `tcomment#DefineType(...)` is specifying that DefineType is a function in the tcomment.vim file in the autoload directory, so vim automatically loads that file when it gets called. Check out `:help autoload-functions`.
Alligator