Stay hungry, Stay foolish

0%

打造Mac下的开发环境(tmux、zsh、vim)

Zsh

mac下默认的shell比较弱,直接换成zsh吧,兼容bash、更高效、更好的自动实例、可定制性高……

安装

  • 查看mac下是否支持
1
2
✗ more /etc/shells | grep zsh
/bin/zsh
  • 安装oh-my-zsh
1
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

插件

  • autosuggestions
  • syntax-highlighting
1
2
3
mkdir -p ~/.zsh/plugins
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.zsh/plugins/zsh-syntax-highlighting

修改配置

1
2
ZSH_CUSTOM=~/.zsh  #开启ZSH_CUSTOM
plugins=(git zsh-autosuggestions zsh-syntax-highlighting) #增加autosuggestions和syntax-highlighting

重新加载配置

1
source ~/.zshrc

Tmux

安装

1
brew install tmux

配置

1
2
3
4
➜  ~ rm -rf .tmux
➜ ~ git clone https://github.com/gpakosz/.tmux.git
➜ ~ ln -s .tmux/.tmux.conf
➜ ~ cp .tmux/.tmux.conf.local .

重新加载tmux.conf

  • 通过命令行
1
tmux source-file /path/to/conf
  • 通过配置
1
bind r source-file ${HOME}/.tmux.conf \; display-message "source-file reloaded"

一些快捷键

快捷键 简介
PREFIX-:new 新建session
PREFIX-$ 重命名session
PREFIX-s 列出所有session(可用上下方向键选择切换)
PREFIX-c 新建window
PREFIX-, window重命名
PREFIX-& kill window
PREFIX-% 垂直切分(切分为两个panel)
PREFIX-“ 水平切分

Theme

Soliarized是笔者见过的最强大(支持的软件真心多)最酷的一个主题包

VIM

基本配置

tab
1
2
3
4
5
set tabstop=4
set cindent shiftwidth=4
set autoindent shiftwidth=4
"自动将tab转成空格
set expandtab
编码识别

原理是严格的编码放前面,宽松的放后面

1
set fencs=ucs-bom,utf-8,gb18030,gbk,gb2312,cp936,latin1

插件逐个说

总览
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Plugin 'VundleVim/Vundle.vim'  "必备,VIM插件管理
Plugin 'mileszs/ack.vim'
Plugin 'mattn/emmet-vim'
Plugin 'ervandew/supertab'
Plugin 'christoomey/vim-tmux-navigator' "与Tmux更好地配合使用
Plugin 'tpope/vim-markdown' "让VIM支持markdown语法高亮
Plugin 'scrooloose/nerdtree' "目录树
Plugin 'scrooloose/nerdcommenter'
Plugin 'majutsushi/tagbar' "
Plugin 'kien/ctrlp.vim' "必备
Plugin 'jiangmiao/auto-pairs' "引号、括号等自动闭合
Plugin 'flazz/vim-colorschemes'
Plugin 'SirVer/ultisnips' "VIM代码片段神器
Plugin 'honza/vim-snippets' "大神们已经写好的一些代码片段库
Plugin 'tpope/vim-dispatch'
Plugin 'tpope/vim-fugitive'
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-repeat'
Plugin 'bling/vim-airline'
Plugin 'Lokaltog/vim-easymotion'
Plugin 'Shougo/neocomplete' "自动补全
Plugin 'mhinz/vim-startify' "VIM打开界面,看个人需要
Plugin 'vim-scripts/wildfire.vim'
Plugin 'vim-scripts/cscope.vim' "与cscope索引配合使用
Plugin 'nathanaelkane/vim-indent-guides'
Plugin 'yonchu/accelerated-smooth-scroll'
Plugin 'sunzy/vim-deploy'
Plugin 'vim-scripts/tlib'
Plugin 'gregsexton/MatchTag'
Plugin 'valloric/MatchTagAlways'
Plugin 'pangloss/vim-javascript'
Plugin 'vimwiki/vimwiki' "随手写写笔记之类的
Plugin 'dahu/diffo' "查看文件的修改情况
NERDTree
1
2
3
4
5
6
:map <leader>n :NERDTree<CR> "设置打开的快捷键
let NERDTreeQuitOnOpen=1
let NERDChristmasTree=1
let g:NERDTreeWinSize=32
map <leader>r :NERDTreeFind<CR>
map <leader>bs :BookmarkToRoot static<CR>
vimwiki

适合做随笔,写代码时有啥灵感,使用+wt呼之而出

配置支持markdown(实际上也没什么卵用)

1
2
3
let g:vimwiki_list = [
\{"path":"~/vimwiki","path_html":"~/vimwiki_html","syntax":"markdown","auto_export":0},
\]
snippets
  • 安装
1
2
Plugin 'SirVer/ultisnips'
Plugin 'honza/vim-snippets'
  • 配置
1
2
3
4
5
6
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
let g:UltiSnipsListSnippets="<c-tab>"
let g:UltiSnipsEditSplit="vertical"
nnoremap <leader>es :UltiSnipsEdit<CR>

使用es便可以打开一个当前文件类型的snippet配置文件(在~/.vim/ultiSnips/下),可以在写代码的同时把snippet也给写了

  • 使用

最新版本已经解决了与supertab的冲突

php.snippets可直接使用

如果想使用php-laravel.snippets可在vimrc中添加如下代码 =>参考

1
autocmd FileType php set ft=php.laravel
cscope
生成cscope
1
2
3
4
mkdir -p ~/data/
cd ~/data
find /Projects/trunk -name '*.php' > ~/data/cscope.files
cscope -b
设置环境变量
1
2
echo export CSCOPE_DB=/Users/test/data/cscope.out >> ~/.zshrc
source ~/.zshrc
插件安装
1
Plugin 'vim-scripts/cscope.vim'
插件配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
if has("cscope")
if filereadable("cscope.out")
cs add cscope.out
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
endif

nnoremap <leader>fa :call cscope#findInteractive(expand('<cword>'))<CR>
nnoremap <leader>l :call ToggleLocationList()<CR>
" s: Find this C symbol
nnoremap <leader>fs :call cscope#find('s', expand('<cword>'))<CR>
" g: Find this definition
nnoremap <leader>fg :call cscope#find('g', expand('<cword>'))<CR>
" d: Find functions called by this function
nnoremap <leader>fd :call cscope#find('d', expand('<cword>'))<CR>
" c: Find functions calling this function
nnoremap <leader>fc :call cscope#find('c', expand('<cword>'))<CR>
" t: Find this text string
nnoremap <leader>ft :call cscope#find('t', expand('<cword>'))<CR>
" e: Find this egrep pattern
nnoremap <leader>fe :call cscope#find('e', expand('<cword>'))<CR>
" f: Find this file
nnoremap <leader>ff :call cscope#find('f', expand('<cword>'))<CR>
" i: Find files #including this file
nnoremap <leader>fi :call cscope#find('i', expand('<cword>'))<CR>
ctags
生成数据文件
1
2
3
4
5
6
7
8
9
cat phpctags.sh
#!/bin/bash

cur_dir=$PWD
cd ~/project/trunk/
find . -name "*.php" > src.files
ctags -R -L src.files
PWD=cur_dir
echo 'Done!'
配置
1
set tags+=~/project/trunk/tags
据说打赏我的人,代码没有BUG