Fix “There was a problem with the editor ‘vi’” on Mac

Share Button

I encountered this issue when I run

and vi opens up. If I input some comment, save and quit. I’ll get this error msg:

and commit will fail.

I think this is because some thing wrong with default vi installed on Mac. I verified by running

This means quit vi returns error code 1. I have no idea why this happen. But I tried with Vim and it doesn’t happen. So the solution is really simple, set default edit to something other than this problematic vi.

To find which vim you are using:

Editing Python code in Vim.

Share Button

Python is relied on indentation, and if you edit python code in Vim, you may found it will mess up your indentation. Here is a simple way to fix it.

Open your file in Vim you will see something like this:

and enter Vim command

to see all white spaces. If you see something like this:

You know you have inconsistent indentation. “^I” means tab, but “print c” statement is indented by space.

How to fix this? Easy.

  1. Edit your .vimrc file to have following:
  2. For the files having indentation issue, run Vim command to fix them:
  3. Now check the file again using “:set list”, and you will see all tabs are gone. They are places by spaces.

Use vim/gvim as a file manager

Share Button

Maybe it is the case that your screen is small or you don’t have enough screens, you cannot open many terminals and editors. In this case, you probably want to use your editor as a file manager like windows explorer. Vim is a perfect tool for that. (Emacs also can do that, but I don’t use Emacs….. sorry)

  • Use :Ex (mnemonic: Explorer) to bring up file explore, and you can view, delete, open, rename, move and etc.
  • You can also use :Sex (Sex?? Split explorer), :Vex (Vertical split explorer), and :Tex (new tab explorer).
  • In file explorer, you can press <F1> to get more awesome feature!
  • Actualy, if you direct vim a directory, it opens file explorer.

Setup gvim/vim color scheme

Share Button

It is very easy to set up gvim/vim color scheme:

  1. Go to http://code.google.com/p/vimcolorschemetest/
  2. Select a file type, and then choose a color scheme you like, save as *.vim into ~/.vim/colors/. If you don’t have that folder, create one.
  3. In your .vimrc file, add “colorscheme *”. Here * is the name of the color scheme you downloaded without suffix “.vim”.
  4. Restart you gvim/vim and enjoy!