Vim:如何使用unix命令输出作为文件名保存到?

时间:2012-09-13 17:45:50

标签: vim command

我想在保存时使用unix命令。命令返回文件路径。如下所示:

pseudo code
:w !command

# I name this command 'mami'
$ MAMI_DIR=~/work echo $MAMI_DIR/$(date "+%Y-%m-%d-%H-%M-%S").txt
#=> /Users/sane/work/2012-09-13-01-58-01.txt

https://gist.github.com/3713132

# my expectation
:w !mami
#=> to save /Users/sane/work/2012-09-13-01-58-01.txt
# or
:mami
#=> to save /Users/sane/work/2012-09-13-01-58-01.txt

但我的exec只返回字符串或错误:

:w !mami
#=> This show only file path, /Users/sane/work/2012-09-13-01-58-01.txt and said "press key"
:w !$(MAMI_DIR=~/work echo $MAMI_DIR/$(date "+%Y-%m-%d-%H-%M-%S").txt)
#=> This return value 127

我如何实现这一目标?这是vim脚本的区域吗?请给我一些建议。

3 个答案:

答案 0 :(得分:3)

你可以做到

:w `mami`

实现你想要的。你实际做的是将输出传递给mami命令。

答案 1 :(得分:0)

只需要mami这样做:

MAMI_DIR=~/work cat >$MAMI_DIR/$(date "+%Y-%m-%d-%H-%M-%S").txt

然后w !mami

答案 2 :(得分:0)

你可以用反引号做到这一点:

:w `mami`
相关问题