如何在 VIM 编辑器中强制关键字自动大写?

发布于 2024-07-08 04:13:49 字数 212 浏览 8 评论 0原文

有人知道如何编辑 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 技术交流群。

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

发布评论

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

评论(2

还在原地等你 2024-07-15 04:13:49

尝试:

:help abbreviations

例如:

:iab begin BEGIN

现在每当您键入“begin”时,它都会被“BEGIN”替换。

Try:

:help abbreviations

For example:

:iab begin BEGIN

Now whenever you type "begin", it will be replaced by "BEGIN".

嘿看小鸭子会跑 2024-07-15 04:13:49

这是一个老问题,但我想我应该补充一下。 接受的答案很好,但它没有说明如何将其限制为仅 sql 文件。 @sigvaldm 下面的评论表明有些人可能不知道该怎么做。

要在 vim 中执行此操作,您需要设置一个自动命令:

 augroup sqlite
     autocmd!
     au BufNewFile,BufRead *.sql iab abort ABORT
     au BufNewFile,BufRead *.sql iab autoincrement AUTOINCREMENT
 augroup END

它的作用是,每当您打开任何结尾带有 .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:

 augroup sqlite
     autocmd!
     au BufNewFile,BufRead *.sql iab abort ABORT
     au BufNewFile,BufRead *.sql iab autoincrement AUTOINCREMENT
 augroup END

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 of sqlite 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.md

Then 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

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