Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MacVim: create new file from command line by using `alias mvim="open -a macvim"`

When I use vim newfilename to open a file and this file does not exit, vim will create a new file with the name newfilename.

However, MacVim does not work in this way --- i.e. mvim newfilename (alias mvim="open -a macvim") will lead to an error: newfilename does not exist

Is there a way to configure MacVim such that mvim newfilename (alias mvim="open -a macvim") will create a new file and open it?

like image 305
Liw Avatar asked Sep 18 '11 00:09

Liw


1 Answers

I'm guessing the error message comes from open, not from vim. You can replace your alias with a function;

mvim () {
    local f
    for f; do
        test -e "$f" || touch "$f"
    done
    open -a macvim "$@"
}

This will create empty files if necessary before opening them.

edit Didn't see @Peter Lyons' comment about this; credit should go to him for first suggesting this solution. I'll be happy to remove this answer if Peter wants to submit his.

like image 155
tripleee Avatar answered Sep 30 '22 18:09

tripleee