简体   繁体   中英

How come when I use the tComment VIM plugin in a .ini file it adds/removes semi-colons instead of hashes as comment?

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM