vim 图像放置

发布于 2024-11-02 09:57:10 字数 187 浏览 3 评论 0原文

在过去的几天里,我一直强迫自己从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

狠疯拽 2024-11-09 09:57:10

自从切换以来,我一直在考虑自动 构建。

Vim 有一个内置的解决方案来解决部分问题:全能补全引擎允许您补全要包含的文件的路径。

如果您开始输入“类似路径”的字符串 - 例如

但对于 widthheight 来说根本没有帮助。

与ACP 可能的解决方案是使用 snipMate 作为 代码段,使用 作为图像路径,捕获路径并将其提供给一些命令行实用程序,用其输出填充 widthheight 属性

编辑事实

证明其他人已经探索了类似的道路,这个脚本很有趣,但它不能在包含空格的文件路径中正常工作. 这是一个稍作修改的版本,效果相当好这另一个似乎很酷,但它是缺少一个关键的部分。

结束编辑

另一个编辑

我已将此代码段添加到 ~/.vim/bundle/snipMate/snippets/html.snippets (注意 $ 之前的缩进是 ):

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

效果很好,但在 HTML_insertImg() 的输出前面加上 0像这样:

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

这个 0 不过有点问题。该系统显然并不完美,但一旦我摆脱了这个烦人的 0 ,它将非常适合我基于 snipMate 的流程的其余部分。

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

结束另一个编辑

扩展 12 英寸重新编辑版本

使用:

您可以:

  • 打开 NERDTree,选择一个图像并点击 b 以获得几乎完整的 标签粘贴到上一个窗口中的光标位置
  • ,或者,如果您Vim 风格允许,输入 :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 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文