Saturday, October 29, 2011

Error in .vimrc

So I copy my .vimrc from my PC to Mac. I put it into ~/. But when start MacVim, there is error message like this:

E488: Trailing characters: nocompatible^M

So the vimrc can't be loaded into MacVim. I googled but their solution doesn't work for me. There is a very simple solution is....


1. In terminal:

$mv ~/.vimrc vimrc
$mvim ~/.gvimrc

2. Then in vim:
:tabe ~/vimrc
:gg
:ctrl+v
:G
:y
:tabp
:p


That means, copy the whole content from "vimrc" to ".gvimrc" in MacVim. So the ".gvimrc" will work well.

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.

Why this blog

I just bought a Mac Mini and began to study the iOS dev. But I'm not familiar with Mac OS, so I write blog here, to recod every progress I get. And I hope this can be helpful to others :)