Friday, October 28, 2011

Vim for Mac

I use vim for many years (on windows), so I also want to use vim on Mac. Because Mac OS is a type of UNIX, so there is a text based vim built-in it. But I want a GUI vim. It seems that MacVim is the best choise for vimer on OSX. You can download it from: https://github.com/b4winckler/macvim, or http://code.google.com/p/macvim/.

After download / install MacVim, there are two method to open it in console:
  • $open -a MacVim
  • $mvim
Let me explain:


1. open -a MacVim
Because MacVim is installed on /Application, so the system allow us to open the app by the name, the path is not needed. It is very handy, but it seems that if you want to edit a file with administrator privilege, "sudo open -a MacVim" can't work. So we need the second method.

2. mvim
mvim is included in the install package of MacVim, you can copy it to a dir, for example, I have a directory: ~/scripts, and I copy mvim into ~/scripts. Then I need to add ~/scripts into the PATH.
Because OSX read the follow configurations when terminal opens (via this):
  • /etc/profile
  • ~/.bash_profile
  • ~/.bash_login
  • ~/.profile
So we can edit ~/.profile and add this line:

export PATH=~/scripts:$PATH

into it. So ~/scripts is added into PATH whenever you open a terminal.
Then in terminal, you can just type:
$mvim <path to file>
or
$sudo mvim <path to system file>
to edit.

No comments:

Post a Comment