vim图像放置 [英] vim image placement

查看:125
本文介绍了vim图像放置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的几天里,我一直强迫自己从Textmate切换到Vim。在大多数情况下,
,在经过一些繁重的Vim配置后,我的效率几乎相同。
我的工作流程的一个方面我没有找到替代品是将文件拖放到Textmate中,其中图像将转换为img标签,文件将转换为require调用。



如何动态构建图像标记和include / require语句?

解决方案

自切换以来,我一直在考虑自动< img> 建设。



Vim内置了解决问题的一部分:omni-completion引擎允许您完成要包含的文件的路径。



如果您开始键入路径 - 像字符串 - 说< img src =images / - 点击< C-x>< C-f> 获取一些可能的完成列表。再加上像ACP这样的自动完成插件,以及snipMate这个过程非常快。



但它没有 width height 的帮助。



一种可能的解决方案是将snipMate用于< img> 代码段,使用< C-x>< C-f> 为图像的路径,捕获路径并将其提供给某个命令行实用程序,填写 width height 属性及其输出。



编辑



事实证明其他人有已经探索过类似的道路,这个剧本很有意思,但它没有' t适用于包含空格的文件路径。 这是一个稍微修改过的版本,效果相当不错。 另一个似乎很酷但它错过了一个关键部分。



END EDIT



另一个编辑



我已将此片段添加到〜/ .vim / bundle / snipMate / snippets / html.snippets (注意 $ 是< Tab> ):

  snippet img custom 
$ {1:`HTML_insertImg()`}

哪个效果很好,但预先输出 HTML_insertImg(),其中 0 ,如下所示:

  0< img src =future_timeline.pngwidth =612height =6370alt =/> 

这个 0 有点问题虽然。系统显然不是很完美,但是一旦我摆脱了这个唠叨的 0 ,它将在我基于snipMate的其余过程中非常合适。



顺便说一下这是第二个修改版我使用的脚本。



END另一个编辑



扩展12重新编辑版本



使用:





你可以:




  • 打开NERDTree,选择一张图片并点击 b 即可获得几乎完整的< img src =imagename.jpgwidth =128height =256alt =/> 标签粘贴在上一个窗口中光标的位置

  • 或者,如果你的Vim风味允许,输入:IMG< CR> 打开原生文件选择对话框,选择一个mage并且几乎完成< img src =imagename.jpgwidth =128height =256alt =/> 标记粘贴在光标在当前窗口中的位置

  • 或者,如果您在终端中,请键入:IMG path / to / file.jpg to有一个几乎完整的< img src =imagename.jpgwidth =128height =256alt =/> 标记粘贴在光标位置在当前窗口中



现在还没有真正解决snipMate解决方案。



<感谢Petr Mach和 @Matteo Riva 实际完成大部分工作。



是的,我显然不是Vim专家。



END EXEXENDED 12RE-EDIT VERSION


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?

解决方案

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 and height.

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 the width and height 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>):

snippet img custom
  ${1:`HTML_insertImg()`}

which works well but prepends the output of HTML_insertImg() with a 0 like this:

0<img src="future_timeline.png" width="612" height="6370" alt="" />

This 0 is a bit of a problem though. The system is obviously not perfect but once I'll get rid of this nagging 0 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:

you can:

  • open NERDTree, select an image and hit 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
  • or, if your Vim flavour allows it, type :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
  • or, if you are in a terminal, type :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 window

The 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

这篇关于vim图像放置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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