Vimr: Opening VimR from the command line

Created on 17 Aug 2014  Â·  11Comments  Â·  Source: qvacua/vimr

It would be great if it was documented how to access VimR from the command line and if the application was aware of the current working directory to open that as the default project.

Use Case

I spend all day in my command line jumping between projects. Being able to type vimr in a directory or vimr /path/to/filename would be huge.

Attempts

I have tried calling open /Applications/VimR.app - this works but doesn't take into account the current working directory.

I have tried running /Applications/VimR.app/Contents/MacOS/VimR but this doesn't appear to work.

Most helpful comment

Incase anyone comes here from Google. Command line tool: https://github.com/qvacua/vimr/wiki#command-line-tool

All 11 comments

:+1: Yes please!

This is the script I use:

#!/bin/bash

open -a VimR.app "$@"

Name it vimr and place it in your path (e.g. /usr/local/bin/vimr). I have mine at ~/bin/vimr.

You can then vimr path/to/directory or vimr path/to/file.

Hint - Use vimr . to open the current directory.

We should include this script in the app bundle and link it to /usr/local/bin/vimr (or another location) at the request of the user.

Thanks so much for the script @dnerdy

I hope you don't mind but I shared this in a blog post

I have found that few people read github issues and annoyingly github issues on new projects are very rarely well indexed by Google.

:+1: for having this in the app bundle.

@dnerdy script is nice, but you miss things like -c,--nomru that mvim has. So for example my default editor as set in the bash is

mvim -f --nomru -c "au VimLeave * !open -a iTerm"

but this doesn't work with the vimr script.

As a small FYI, using the open command does not allow one to create files, which does work correctly with mvim (aka /Applications/MacVim.app/Contents/MacOS/Vim -g my_file)

It also, as written, does not permit passing flags to Vim, such as the handy -R, which open interprets as its own "Reveal Finder" action. If one wishes to continue using open, the correct command is open -a VimR.app --args "$@"

Just my two cents but you probably want a proper shell tool that can communicate with the GUI app, so you can support stuff like

# pipe text into new editor window
grep fail messages.log | vimr
# wait for editor window to close before terminating
EDITOR="vimr -w" git commit -a

The script by @dnerdy can serve as a temporary solution. However, for really good CL support like mvim, it will require some thought and work. Probably via #51 (or #17 which would mean _a lot_ more work).

Thanks @dnerdy, it works! ツ

But I agree with @qvacua!

Incase anyone comes here from Google. Command line tool: https://github.com/qvacua/vimr/wiki#command-line-tool

Was this page helpful?
0 / 5 - 0 ratings