0

I want to use unix command on save. Command return file path. Like below:

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

But my exec is only return string or errors:

: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

How do I achieve this? Is this the area of vim script? Please give me suggestion.

1
  • What you were requesting with the title (before I fixed it) is autocmd BufWritePost {pattern} !mami: running command after you save file, not running command to get filename to save to. Be careful with wording. Commented Sep 13, 2012 at 17:57

3 Answers 3

4

You can do

:w `mami`

to achieve what you want. What you were actually doing was piping output to the mami command.

Sign up to request clarification or add additional context in comments.

1 Comment

I want separate solutions to get filename to save to, and actually save file, so this is better. thanks.
0

Just make mami do it:

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

and then w !mami

Comments

0

You can do this with backticks:

:w `mami`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.