vim 图像放置 [英] vim image placement

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

问题描述

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

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

解决方案

自从切换以来,我一直在考虑自动构建 <img>.

Vim 有一个针对部分问题的内置解决方案:omni-completion 引擎允许您完成要包含的文件的路径.

如果你开始输入一个类似路径"的字符串——比如 <img src="images/——点击 <C-x><C-f> 列出可能的补全列表.再加上像 ACP 和 snipMate 这样的自动补全插件,这个过程真的很快.

但是对于 widthheight 完全没有帮助.

一种可能的解决方案是使用 snipMate 作为 <img> 片段,使用 <C-x><C-f> 作为图像的路径,捕获路径并将其提供给一些命令行实用程序,用其输出填充 widthheight 属性.

编辑

原来其他人已经探索过类似的道路,.

结束另一个编辑

加长 12" 重新编辑版本

与:

你可以:

  • 打开NERDTree,选择一张图片并点击b,得到一个几乎完整的<img src="imagename.jpg" width="128" height="256" alt=""/> 标签粘贴在上一个窗口中光标所在的位置
  • 或者,如果您的 Vim 风格允许,输入 :IMG 以打开本机文件选择对话框,选择图像并获得几乎完整的 <img src="imagename.jpg" width="128" height="256" alt=""/> 标签粘贴在当前窗口的光标位置
  • 或者,如果您在终端中,输入 :IMG path/to/file.jpg 以获得几乎完整的 <img src="imagename.jpg" width="128" height="256" alt=""/> 标签粘贴在当前窗口的光标位置

snipMate 解决方案现在还没有真正成熟.

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

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

结束 12" 重新编辑版本

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天全站免登陆