更改 vim 或 vi 解释文件的方式

发布于 2024-12-21 13:02:45 字数 185 浏览 6 评论 0原文

所以我使用 vim (vi) 在命令行上进行编辑。每当我在以 .php、.pl、.cgi、.pm 等结尾的文件中进行编码时,它都会将其与它的语言相匹配,并进行正确的语法突出显示。但是,我正在编写一些 Perl 脚本,并且需要一些扩展名为“.lib”的单独文件。有没有办法让 vim 将其解释为 .pl 文件?现在它只是用红色突出显示所有内容,看起来很糟糕。

So I am using vim (vi) to edit on command line. Whenever I code in a file that ends in .php, .pl, .cgi, .pm, etc, it matches it up with what language it is and does the proper syntax highlighting. However, I am writing some perl scripts and I am requiring some separate files with the extension ".lib". Is there a way that I could have vim interpret this as a .pl file? right now it just highlights everything in red and looks pretty bad.

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

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

发布评论

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

评论(2

就像说晚安 2024-12-28 13:02:45

:set filetype=pl,如果你希望这种情况一直发生,请添加

au BufNewfile,BufRead *.lib set filetype=pl

到你的 .vimrc

:set filetype=pl, if you want this to happen all the time, add

au BufNewfile,BufRead *.lib set filetype=pl

to your .vimrc

乖乖 2024-12-28 13:02:45

您可能正在寻找 autocmd 命令,它将根据文件名(或其他条件?)执行一些命令?

尝试将类似的内容添加到您的 ~/.vimrc 文件中:

autocmd BufNewFile,BufRead *.lib set syntax=perl

You're probably looking for the autocmd command, which will execute some commands based on filenames (or other criteria?)

Try adding something like this to your ~/.vimrc file:

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