当我在 .ini 文件中使用 tComment VIM 插件时,为什么它会添加/删除分号而不是散列作为注释?

发布于 2024-09-28 13:44:57 字数 331 浏览 3 评论 0原文

我在 Pylons/Python 项目中编辑 development.ini 文件时使用 gVIM 和 tComment 插件。默认的 development.ini 文件使用井号 # 符号注释掉行,这是 Python 中注释行的标准方法。但是,当我尝试使用 gVIM 中的 tComment 键盘快捷键取消注释行时,我没有看到 # 消失。相反,我看到一个分号被添加到行的开头。

如何更正 tComment 的行为,以便它在 Pylons .ini 文件中添加或删除 #s,而不是添加或删除分号?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不寐倦长更 2024-10-05 13:44:57

在自动加载目录中的 tcomment.vim 文件中,您应该找到如下所示的列表:

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

在其中您将找到这一行:

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

假设您不需要太频繁地注释 windows .ini 文件,你可以将其更改为:

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

更新:

这是一个稍微好一点的选择,因为你不必编辑除 vimrc 之外的任何内容。由于您的 vimrc 通常首先加载,因此我们尝试定义的任何内置文件类型都会由上述文件重新定义,因此让我们自己制作:

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

我们首先将 .ini 文件设置为我们自己的文件类型 pythonini,然后为其添加我们自己的 tcomment 定义。

为了让你的 vimrc 保持良好和可移植性,你可能需要在尝试调用它之前检查我们是否有 tcomment:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文