vim 图像放置
在过去的几天里,我一直强迫自己从 Textmate 切换到 Vim。 在大多数情况下,经过一些繁重的 Vim 配置后,我的效率几乎是一样的。 我还没有找到替代工作流程的一方面是将文件拖放到 Textmate 中,其中图像将转换为 img 标签,文件将转换为 require 调用。
如何动态构建图像标签和 include/require 语句?
For the last few days I've been forcing myself to switch from Textmate to Vim.
for the most part, my efficiency is pretty much the same after some heavy Vim configuration.
one aspect of my workflow I haven't found a replacement for is the drag and drop of files into Textmate, where images would be transformed into img tags and files would be transformed into require calls.
How can I dynamically build an image tag, and an include/require statement?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
自从切换以来,我一直在考虑自动
构建。
Vim 有一个内置的解决方案来解决部分问题:全能补全引擎允许您补全要包含的文件的路径。
如果您开始输入“类似路径”的字符串 - 例如
但对于
width
和height
来说根本没有帮助。与ACP 可能的解决方案是使用 snipMate 作为
代码段,使用
作为图像路径,捕获路径并将其提供给一些命令行实用程序,用其输出填充width
和height
属性编辑事实
证明其他人已经探索了类似的道路,这个脚本很有趣,但它不能在包含空格的文件路径中正常工作. 这是一个稍作修改的版本,效果相当好这另一个似乎很酷,但它是缺少一个关键的部分。
结束编辑
另一个编辑
我已将此代码段添加到
~/.vim/bundle/snipMate/snippets/html.snippets
(注意$
之前的缩进是
):效果很好,但在
HTML_insertImg()
的输出前面加上0
像这样:这个
0
不过有点问题。该系统显然并不完美,但一旦我摆脱了这个烦人的0
,它将非常适合我基于 snipMate 的流程的其余部分。顺便说一句,这是我使用的脚本的第二个修改版本。
结束另一个编辑
扩展 12 英寸重新编辑版本
使用:
identify
~/.vim/plugins/
~/.vim/nerdtree_plugin
中,您可以:
b
以获得几乎完整的标签粘贴到上一个窗口中的光标位置
:IMG
打开本机文件选择对话框,选择一个图像并获得几乎完整的标签粘贴在当前窗口中光标的位置
:IMG path/to/file.jpg
将几乎完整的标签粘贴到当前窗口中光标的
位置snipMate 解决方案目前还没有真正成熟。
感谢 Petr Mach 和 @Matteo Riva 实际完成了大部分工作。
是的,我显然不是 Vim 专家。
结束 12 英寸加长重新编辑版本
I've been thinking about that automatic
<img>
building since switching.Vim has a built-in solution for one part of the problem: the omni-completion engine allows you to complete the path of a file you want to include.
If you begin to type a "path-like" string — say
<img src="images/
— hit<C-x><C-f>
for a little list of possible completions. Coupled with an auto-completion plugin like ACP, and snipMate the process is really fast.But it doesn't help at all for
width
andheight
.A possible solution would be to use snipMate for the
<img>
snippet, use<C-x><C-f>
for the image's path, capture the path and feed it to some command line utility, fill thewidth
andheight
attributes with its output.EDIT
It turns out others have already explored a similar road, this script is interesting but it doesn't work properly with file paths containing spaces. Here is a slightly modified version that works reasonably well. This other one seems to be very cool but it's missing a crucial piece.
END EDIT
ANOTHER EDIT
I've added this snippet to
~/.vim/bundle/snipMate/snippets/html.snippets
(attention the indent before$
is a<Tab>
):which works well but prepends the output of
HTML_insertImg()
with a0
like this:This
0
is a bit of a problem though. The system is obviously not perfect but once I'll get rid of this nagging0
it's going to fit rather nicely within the rest of my snipMate-based process.By the way here is a second modified version of the script I use.
END ANOTHER EDIT
EXTENDED 12" RE-EDIT VERSION
With:
identify
~/.vim/plugins/
~/.vim/nerdtree_plugin
you can:
b
to have an almost complete<img src="imagename.jpg" width="128" height="256" alt="" />
tag pasted at the cursor's position in the previous window:IMG<CR>
to open a native file selection dialog, chose an image and have an almost complete<img src="imagename.jpg" width="128" height="256" alt="" />
tag pasted at the cursor's position in the current window:IMG path/to/file.jpg
to have an almost complete<img src="imagename.jpg" width="128" height="256" alt="" />
tag pasted at the cursor's position in the current windowThe snipMate solution is not really baked right now.
Thanks to Petr Mach and @Matteo Riva for actually doing most of the work.
And yes, I'm obviously not a Vim expert.
END EXTENDED 12" RE-EDIT VERSION