逐块更改文件类型(或其他Vim设置)? [英] Change filetype (or other Vim settings) blockwise in a file?

查看:65
本文介绍了逐块更改文件类型(或其他Vim设置)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Vim中编写了很多Perl.通常,我只是一起整理一些CGI脚本,然后将CSS放入程序代码中.因此,最近我问自己是否可以在代码中围绕这些块添加一些特定于Vim的注释,以便vim可以将特定区域突出显示为不是层叠的样式表,而不是Perl脚本.

I program a lot of Perl in Vim. Often I just hack together some CGI script and put the CSS right into the program code. So lately I asked myself if it was possible, to put some Vim-specific comments around such blocks in my code, so that vim highlights the specific area not as a Perl script, but as a cascading stylesheet.

与Mojolicious一起使用时,这也很整洁,您可以将整个模板仅嵌入到DATA区域中,但随后会丢失所有HTML高亮显示.

This also would be neat when working with Mojolicious where you can embed entire templates just into the DATA-area but lose all the highlighting of the HTML then.

当然,我可以在文件类型/突出显示之间手动切换.但我想知道是否有更好的方法.

Of course, I could switch manually between the filetypes/highlighting. But I wonder if there is better way.

谢谢, 斯文

推荐答案

您可以为单个文件设置多种文件类型:

You can have multiple filetypes set for a single file :

:set ft=perl.css

这样一来,您将获得两种语言的全功能(如果有的话,还提供摘录)和半正确的高亮显示:如果将CSS规则放在引号中,它将被高亮显示为字符串.

With that you get omnicompletion (and snippets if applicable) for both languages and semi-correct highlighting: if you put your CSS rules in quotes it will be highlighted as a string.

(昨天)我刚刚发现了一个受Emacs功能启发的酷插件,名为 NrrwRgn .它允许您选择代码的区域",例如说说Perl文件的CSS部分,然后在您为:set ft=css的临时窗口中对其进行编辑.每次保存都会反映在原始窗口中.在处理包含PHP/HTML/JS/CSS的PHP模板时非常有用.

I've just found (yesterday) a cool plugin inspired by an Emacs feature called NrrwRgn. It allows you to select a "region" of code, say the CSS part of your Perl file and edit it in a scratch window for which you :set ft=css. Each save is reflected in the original window. Very useful when dealing with PHP templates full of PHP/HTML/JS/CSS.

这篇关于逐块更改文件类型(或其他Vim设置)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆