使用当前打开的文件作为参数从 Vim 运行 shell 脚本
我刚刚开始使用 Vim。
这是一个我在 BBedit 中经常使用的 shell 脚本。
#!/bin/sh
filename=$(basename "${BB_DOC_PATH##*/}" .ly)
directory=${BB_DOC_PATH%/*}/
cd "${directory}"
lilypondPDFoutput="${directory}"$filename".pdf"
/Applications/Lilypond.app/Contents/Resources/bin/ lilypond -dno-point-and-click -ddelete-intermediate- files "$BB_DOC_PATH"
wait
open "${lilypondPDFoutput}"
BB_DOC_PATH 是一个变量,表示当前打开文件的路径。 (例如 /Users/me/Documents/file.ly
)
我该如何将此脚本放入我的 .vimrc 中,并使用 :typeset
等简单命令调用它?
注意:我正在排版 Lilypond 文件。
I've just started using Vim.
Here is a shell script which I use frequenty from within BBedit.
#!/bin/sh
filename=$(basename "${BB_DOC_PATH##*/}" .ly)
directory=${BB_DOC_PATH%/*}/
cd "${directory}"
lilypondPDFoutput="${directory}"$filename".pdf"
/Applications/Lilypond.app/Contents/Resources/bin/ lilypond -dno-point-and-click -ddelete-intermediate- files "$BB_DOC_PATH"
wait
open "${lilypondPDFoutput}"
BB_DOC_PATH is a variable which represents the path of the currently open file. (e.g. /Users/me/Documents/file.ly
)
How would I go about placing this script in my .vimrc, and invoking it with simple command like :typeset
?
Note: I am typesetting a Lilypond file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用类似的内容:
如果 PATH 中有 your_script ,它应该可以正常工作。请参阅 :! 和 文档的文件修饰符。
You could use something like:
If you have your_script in the PATH it should work fine. See :! and file modifiers for docs.
OP询问如何将脚本放入.vimrc中。由于 Vim 导入文件进行行延续的奇怪方式,这变得有点棘手。它会是这样的:
这是现在在完全不同的环境中实际为我工作的内容(Lilypond/Win32;Vim for Cygwin)。
注意:Lilypond/Win32 不理解正斜杠路径。因此我消除了其论证中的路径。你也可以这样做。您已经用“cd”设置了路径。另外,对于我的环境,我取出了点击选项以及“等待”,并将“打开”更改为“cygstart”。那时 shell 部分已经足够短了,我不需要 Vim 所要求的相当神秘的行延续。同时,我添加了快捷操作符,以便任何阶段的错误都会停止该过程。
The OP asked how to place the script in the .vimrc. This gets just a little tricky because of the odd way Vim import files do line continuation. It would be something like this:
Here's what is actually now working for me in quite a different environment (Lilypond/Win32; Vim for Cygwin).
Notes: Lilypond/Win32 does not understand forward-slash paths. Therefore I eliminated the path in its argument. You could do the same. You have already set the path with "cd". Also for my environment I took out the point and click option, as well as the "wait", and changed "open" to "cygstart". At that point the shell part was short enough I did not need the rather arcane line continuation demanded by Vim. At the same time I added shortcut operators so that an error at any stage would stop the process.