如何在 VIM 编辑器中强制关键字自动大写?
有人知道如何编辑 VIM 的语法文件以便关键字自动大写吗? 我需要这样做,以使我的编码风格与团队中的其他开发人员保持一致。
我使用的是 VIm 7.2 版(实际上是 gVIM),我使用的语法文件是 Progress.vim 文件(随 VIM 自动安装在 Syntax 目录下)。 我对文件做了一些调整,因为我不喜欢某些事情的完成方式,但它基本上是相同的。
TIA
Does anybody know how to edit a syntax file for VIM so that keywords are capitalized automatically? I need to do this to keep my coding style consistent with the rest of the developers in my team.
I'm using VIm version 7.2 (actually gVIM) and the syntax file I'm using is the Progress.vim file (installed automatically with VIM under the Syntax directory). I have made a couple tweaks to the file as I didn't like how some things were done, but it is mostly the same.
TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试:
例如:
现在每当您键入“begin”时,它都会被“BEGIN”替换。
Try:
For example:
Now whenever you type "begin", it will be replaced by "BEGIN".
这是一个老问题,但我想我应该补充一下。 接受的答案很好,但它没有说明如何将其限制为仅
sql
文件。 @sigvaldm 下面的评论表明有些人可能不知道该怎么做。要在 vim 中执行此操作,您需要设置一个自动命令:
它的作用是,每当您打开任何结尾带有
.sql
的文件时,它都会执行缩写。 我在线获得了sqlite
关键字的保留字列表,这是我使用的链接,但它可能已失效,因此只需搜索它即可:https://github.com/AnanthaRajuC/Reserved -Key-Words-list-of-various-programming- languages/blob/master/language-files/SQLite%20Reserved%20Keywords.md然后我将其复制粘贴到缓冲区中并设置一个宏来写入所有关键字的缩写。 效果非常好。 如果您想了解有关自动命令的更多信息:
:help autocmd
This is an old question, but I thought I'd add to it. The accepted answer is good, but it doesn't say how to constrain it to only
sql
files. @sigvaldm's comment underneath shows that some people may not know how to do that.To do it in vim, you set up an autocommand:
What this does is that whenever you open any file with a
.sql
on the end of it, it'll do the abbreviations. I got a reserved word list ofsqlite
keywords online, this is the link I used but it could be dead so just search it up: https://github.com/AnanthaRajuC/Reserved-Key-Words-list-of-various-programming-languages/blob/master/language-files/SQLite%20Reserved%20Keywords.mdThen I copy-pasted it into the buffer and set up a macro to write abbreviations for all the keywords. It works really well. If you wish to learn more about autocommands:
:help autocmd