Qiang Blog

Just another zhangjingqiang's blog.

How to use vim 7.4 after install it by brew on MacOS

Problem

After install vim 7.4 by brew:

brew install vim

Type brew info vim, will show:

vim: stable 7.4.891, HEAD
Vi "workalike" with many additional features
http://www.vim.org/
Conflicts with: ex-vi
/usr/local/Cellar/vim/7.4.891 (1612 files, 28M) *
  Built from source
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/vim.rb
...

But if type vim, will show:

VIM - Vi IMproved
  version 7.3
...

The reason is the PATH.

Solution

Install macvim:

brew install macvim

Add these settings to ~/.bashrc or ~/.zshrc:

alias vi='/Applications/MacVim.app/Contents/MacOS/Vim'
alias vim='/Applications/MacVim.app/Contents/MacOS/Vim'
alias gvi='/Applications/MacVim.app/Contents/MacOS/Vim -g'

Then type vim will use 7.4 version.

Reference

https://www.reddit.com/r/vim/comments/2ukp5j/starting_homebrew_version_of_vim/

mac vim

在全新Ubuntu系统搭建Python开发环境

假如你在VirtualBox上安装了Ubuntu Server,用SSH连接的话,查看进程:

$ ps aux | grep sshd

验证SSH是否启动。

没有安装的话,执行下面命令:

$ sudo apt-get install ssh

设置语言

$ sudo locale-gen ja_JP.UTF-8
$ sudo dpkg-reconfigure locales

设置.bashrc中语言设定用的环境变量

export LANGUAGE=ja_JP:ja
export LANG=ja_JP.UTF-8

安装Python

安装apt包

$ sudo apt-get -y update
$ sudo apt-get -y upgrade
$ sudo apt-get -y install build-essential
$ sudo apt-get -y install libsqlite3-dev
$ sudo apt-get -y install libreadline6-dev
$ sudo apt-get -y install libgdbm-dev
$ sudo apt-get -y install zlib1g-dev
$ sudo apt-get -y install libbz2-dev
$ sudo apt-get -y install sqlite3
$ sudo apt-get -y install tk-dev
$ sudo apt-get -y install zip

安装Python相关的包

# 安装python-dev
$ sudo apt-get -y install python-dev

# 安装Distribute
$ sudo chmod -R 0775 /usr/local
$ sudo chgrp -R bpbook /usr/local
$ wget http://python-distribute.org/distribute_setup.py
$ sudo python distribute_setup.py

确认Python版本

$ python -V

安装easy_install和pip

$ wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
$ sudo python get-pip.py

确认pip的版本

$ pip --version

安装virtualenv

$ pip install virtualenv

确认virtualenv的help

$ virtualenv --help

virtualenv的用法

确认安装的包

$ pip freeze

用virtualenv创建虚拟环境

$ export VIRTUALENV_USE_DISTRIBUTE=true
$ mkdir ~/work
$ cd ~/work
$ virtualenv env

执行虚拟环境

$ source env/bin/activate

确认虚拟环境的版本

(env) $ pip freeze
distribute==0.6.24
wsgiref==0.1.2

退出虚拟环境

(env) $ deactivate

virtualenvwrapper

安装virtualenvwrapper

$ pip install virtualenvwrapper

设置.bashrc

if [ -f /usr/local/bin/virtualenvwrapper.sh ]; then
  export WORKON_HOME=$HOME/.virtualenvs
  source /usr/local/bin/virtualenvwrapper.sh
fi

重新加载.bashrc

$ source ~/.bashrc

确认mkvirtualenv的帮助

$ mkvirtualenv --help

创建虚拟环境

$ mkvirtualenv newenv

确认虚拟环境

$ ls -la $HOME/.virtualenvs

执行虚拟环境

$ workon newenv

虚拟环境一览

$ workon

删除虚拟环境

$ rmvirtualenv newenv

适用指定版本的Python

$ mkvirtualenv --python=/usr/bin/python2.7 newenv2

确认虚拟环境的Python

(newenv2) $ python -v

设置Mercurial

安装Mercurial

$ sudo pip install mercurial

确认Mercurial

$ hg --version

创建库

设置.hgrc的用户名和邮件地址

[ui]
username=bpbook <bpbook@beproud.jp>
editor = vim

[extensions]
graphlog=
color=
pager=

[pager]
pager=LESS='FSRX' less

hg init(初始化库)

$ mkdir ~/hgtest
cd ~/hgtest
hg init

操作文件

hg status(确认状态)

$ touch test.txt
$ hg status

? test.txt

hg add(添加文件)

$ hg add test.txt
$ hg status

A test.txt

hg commit(提交)

$ hg commit 

test commit

...

确认编辑器

$ echo $EDITOR
vim

hg diff(确认区分)

$ hg status
M test.txt

$ hg diff

diff -r 23742103740 test.txt
...

hg revert(取消编辑)

$ hg revert test.txt

hg rollback(取消提交)

$ hg rollback
$ hg status

A test.txt

hg log(确认提交日志)

$ hg log

编辑器

Vim

编辑.vimrc

Python用的设定

syntax on
filetype plugin indent on

准备配置Python的文件

$ mkdir ~/.vim
$ mkdir ~/.vim/ftplugin
$ touch ~/.vim/ftplugin/python.vim

把下面的内容添加到python.vim文件中

setl expandtab
setl tabstop=4
setl shiftwidth=4
setl softtabstop=4

行尾空格删除的设置

autocmd BufWritePre * :%s/\s\+$//ge

一行80文字换行的设置

setlocal textwidth=80

Emacs

创建.emacs文件

$ touch ~/.emacs

缩进空格

(setq indent-tabs-mode nil)
(global-font-lock-mode 1)

Good Wiki

开发Python的Tips

感应模式

$ python
>>> import sys
>>> sys.path
...

安装IPython

$ pip install IPython

安装pep8(编码样式检查)

$ pip install pep8

安装pyflakes(语法检查/模型)

$ pip install pyflakes

pdb(调试器)

添加pdb的代码

def add(x,y)
  return x + y

x = 0
import pdb; pdb.set_trace()
x = add(1, 2)

执行pdb的例子

$ python pdbtest.py
> pdbtest.py(7)<module>()
-> x = add(1, 2)
(Pdb)

The Zen of Python

>>> import this

参考资料

Pythonプロフェッショナルプログラミング第1章

emacs mercurial python ubuntu vim