稀有猿诉

十年磨一剑,历炼出锋芒,说话千百句,不如码二行。

训服你的Mac

天下武功唯快不破,提升效率是提升战斗力的唯一途径,而一个舒适且高效的开发环境是保证效率的重要方面,对于习惯了Windows和Linux的人来说,习惯使用Mac还是需要一定的时间的,这是就总结一些,如何配置并习惯Mac。

Mac上面的常用快捷键

在Windows上面有一些常用的快捷键,比如像Ctrl+W, Ctrl+F等等,还是非常有用的。在Mac上很多快捷键都是CMD键加上其他键组合的(如果是虚拟机的话,就是Windows的那个键)。

  • CMD+R(先按CMD,再按r键)– 刷新Safari当前页,与Windows上的F5一样
  • CMD+UP或者HOME–滚动网面到最上端
  • CMD+DOWN或者END–滚动网页到最下面
  • CMD + LEFT – 把光标跳到行首,这个在编辑时常用
  • CMD + RIGHT – 把光标跳到行尾
  • CMD + W – 关闭当前的TAB
  • CMD + S – 保存文档
  • 但是经终端里面的快捷键是跟Linux是一样的,比如Ctrl+W是删除掉一个字, Ctrl+C终止一个进程

配置终端

对于开发者来讲,命令行始终都是一个非常好的工具,无论是什么平台,虽然苹果以GUI著称,但是命令行还是很有用处。Mac的Shell默认是bash,因为它是Unix的一个分支,所以使用起来跟Ubuntu几乎一样,常用的命令,常见的配置完全一样。

但是默认的终端很难看,也不好用,需要一些配置,打开终端的Preferences,选择一个Profile,然后进行一些颜色,字体,大小可以按照自己的风格来,在Shell一栏的“When the shell exits:”选择Close if the shell exited cleanly。然后,Prompt before closing选择Only if there are processes other than the login shell and …

安装XCode时,一定要把命令行工具集也都安装上。

给终端配色

在$HOME目录下,编辑.bash_profile文件,如果没有就自己创建一个,在里面最下面输入:

1
2
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced

具体这是啥意思,可以参考这篇文章

添加alias

同样,在.bash_profile文件中添加一些自己喜欢的alias

1
alias grep='grep -rnIE'

配置vim

默认的Mac带有vim,但是还需要一些配置:

在$HOME下面创建一个.vimrc文件,并在里面输入:

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
" An example for a vimrc file.
"
" Maintainer:   Bram Moolenaar <Bram@vim.org>
" Last change:   2011 Apr 15
"
" To use it, copy it to
"     for Unix and OS/2:  ~/.vimrc
"          for Amiga:  s:.vimrc
"  for MS-DOS and Win32:  $VIM\_vimrc
"        for OpenVMS:  sys$login:.vimrc

" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
  finish
endif

" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

if has("vms")
  set nobackup        " do not keep a backup file, use versions instead
else
  set backup     " keep a backup file
endif
set history=50     " keep 50 lines of command line history
set ruler        " show the cursor position all the time
set showcmd       " display incomplete commands
set incsearch        " do incremental searching

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")

" Don't use Ex mode, use Q for formatting
map Q gq

" CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>

" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
  set mouse=a
endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

" Only do this part when compiled with support for autocommands.
if has("autocmd")

  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  " Also don't do it when the mark is in the first line, that is the default
  " position when opening a file.
  autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

  augroup END

else

  set autoindent      " always set autoindenting on

endif " has("autocmd")

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
  command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
        \ | wincmd p | diffthis
endif

set nu
set sm
set si
set cindent
set smarttab
set ts=4
set shiftwidth=4
set expandtab
set mouse=a
set nobackup
let g:neocomplcache_enable_at_startup = 1
colorscheme desert

如果对自带的vim不满意,可以使用MacVim,这个功能更为强大,且支持GUI操作。

配置git

这个就是配置常用的git属性:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[color]
  diff = true
 status = true
    interactive = auto
  branch = true
[core]
  editor = /usr/bin/vim
  autocrlf = false
 filemode = false
[merge]
  tool = vimdiff
[alias]
  co = checkout
  ci = commit
  st = status
  br = branch
[push]
  default = upstream

如果你也有使用Mac的一些技巧,请与我分享。

Comments