我目前正在尝试从 Coda(Mac IDE)切换到 Vim。我对 Coda 的喜爱和我对 Vim 的了解无法替代的一件事就是所谓的“剪辑”。基本上,您输入“new”,然后按 TAB 键,文本就会被基本的 XHTML 页面替换。您可以根据需要添加任意数量的关键字/剪辑组合。
到目前为止,我能用 Vim 得到的最多就是创建一个包含我的剪辑的新文件,然后在 Vim 中使用 :r FILE 来插入它,但这不是一个非常优雅的解决方案,因为我必须在每个目录中携带这些剪辑,所以我有一个要使用剪辑的文件。
那么假设我已经正确解释了事情,我的选择是什么?
I'm currently trying to switch from Coda (a Mac IDE) to Vim. One thing I loved about Coda and my knowledge of Vim cannot replace were the so-called "clips". Basically, you type, say, "new", press TAB, and the text is replaced with a basic XHTML page. And you can add as many keyword/clips combinations as you want.
The most I could get with Vim so far was to create a new file containing my clip, and then use :r FILE in Vim in order to get it inserted, but this is not a very elegant solution, as I'd have to carry these clips around in every directory I have a file I want to use my clips with.
So assuming I've explained things properly, what would be my choices?
发布评论
评论(3)
对于各种编辑器,有一个名为“snippets”的功能,该选项卡将常见文本的开头(如 HTML div 或 C 函数定义)扩展为该代码的骨架。
有几个 vim 插件可以提供此功能。我的书签列表顶部有两个:
我最近听说了另一个使用片段进行快速 HTML 编辑的插件:
检查这些内容,看看它们是否接近您正在寻找的内容。
另外,您可以在 vim 中定义默认的
BufNewFile
操作 - 如果文件尚未自动存在,它可以让您读取文件的框架。将这些(或等效内容)放入您的
.vimrc
(不带前导冒号)中,以便每次运行 vim 时自动设置它们。For various editors, there's a functionality called '''snippets''' which tab expands the beginnings of common text (like a HTML div, or C function definition) into a skeleton for that code.
There's a couple vim plugins that present this functionality. Two off the top of my bookmark list:
I heard of another plugin for quick HTML editing that uses snippets recently:
Check those out and see if they're near what you're looking for.
Also, you can define a default
BufNewFile
action in vim - which lets you read in a skeleton for a file if it doesn't already exist automatically.Put those (or the equivalent) in your
.vimrc
(w/o the leading colon) to have them set up automatically every time you run vim.聚会已经很晚了,但是:
我会推荐像 Dash 这样的东西,因为这些片段可以在所有地方使用你的应用程序。
当您的肌肉记忆开始依赖于特定的片段时,这可能是一个巨大的好处,并且还可以简化从一个编辑器到另一个编辑器的过渡,因为您的片段是独立的。
有时我发现自己在邮件之类的东西中使用片段发送给其他人,或者在我尚未配置的远程计算机上的 Vim 终端中,将它们全部准备好真是太好了。
现在我们需要的是一个跨平台解决方案,可以与您一起移动到同事的机器上!
Very late to the party, but:
I would recommend something like Dash for this, because the snippets are then available across all your apps.
This can be a significant bonus as your muscle-memory starts to rely on particular snippets, and can also ease the transition from one editor to the other, because your snippets are independent.
Sometimes I find myself using snippets in something like Mail to send to someone else, or in a Vim terminal on a remote machine I haven't configured, and it's great to have them all there at the ready.
Now all we need is a cross-platform solution which moves with you to a colleague's machine!
除了各种代码片段插件之外,Vim 还内置了缩写功能,使用
:ab[breviate]
命令。例如,您可以这样定义:
然后,当您输入
时,它将扩展为全文。上例中的^M
实际上是使用
在字符串定义中插入的回车符。As well as the various snippet plugins, Vim also has an abbreviation feature built in, using the
:ab[breviate]
command.For example you can define this:
Then when you type
<h<SPACE>
it will expand into the full text. The^M
in the example above are actually carriage returns inserted in the string definition with<ctrl-V><RETURN>
.