前言
重新配置了一下自己的Mac的编程环境,毕竟新年新气象嘛,主要是iTerm2、Zsh、Vim优化、Consolas字体、NoisyTyper,这些的相关配置。工欲利其事必先利其器,好的编码环境可以提升我们的打码的幸福感。好的编码环境包括
美观(视觉),声音(听觉),流畅度(触觉),工作环境(嗅觉,味觉)等多个方面。后面有几张配置后的图片感受一下,主要看字体和配色
(有些人可能觉得比较丑,个人喜欢黑紫,配色和字体有很多选择,各有所好,求别喷 XD)。
此处输入图片的描述此处输入图片的描述 准备阶段:器
iTerm2:是os系统中的一个替代终端。主要优点:屏幕分割(可以水平分割和垂直分割),选中即复制,快速查找(command+f),配色字体自定义化,自定义快捷键等。Consolas:微软下最好看的字体之一,个人认为很适合程序员,除开字体好看外,主要原因是它的数字“0”字加入了一斜撇,以方便与字母“o”分辨。这也是我和它结缘的主要缘由,当年在某次acm比赛中,就是因为肉眼无法分辨是0还是o,遗憾至今。Zsh:zsh和bash一样是Shell的一种。相比bash:更高效、更好的自动补全、更好的文件名展开(通配符展开)、更好的数组处理、可定制性高。mac下自带了zsh,无需再安装。Vim:是一个类似于Vi的著名的功能强大、高度可定制的文本编辑器,在Vi的基础上改进和增加了很多特性。和Emacs并列成为类Unix系统用户最喜欢的编辑器。估计大家都很熟悉,不做累述。NoisyTyper:一款提升你打字逼格的软件,可以让你打字的时候发出打字机的声音,咔咔咔这样。上面几个安装都比较简单,教程也比较多。这里主要讲一下mac下consolas字体的安装。
$ brew install cabextract$ cd~/Downloads$ mkdir consolas$ cd consolas$ curl -O http://download.microsoft.com/download/f/5/a/f5a3df76-d856-4a61-a6bd-722f52a5be26/PowerPointViewer.exe$ cabextract PowerPointViewer.exe$ cabextract ppviewer.cab$ open CONSOLA*.TTF
最后按下弹出窗口的安装键就ok了。
打磨阶段:利器
上面的工具准备好了后,就可以开始配置这些工具了。
Zsh配置
oh-my-zsh:一套强大的开源zsh配置文件。安装如下:
// 使用curl安装$ sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"// 或者使用wget安装$ sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"// 安装后重新载入配置$ source .zshrc
oh-my-zsh主题: oh-my-zsh有多款配套主题,点击前面的主题链接可以看到所有主题。这里主要介绍下agnoster主题。修改zsh配置文件(~/.zshrc)中的主题属性为agnoster即可。官方图如下:
此处输入图片的描述安装这个主题需要额外安装powerline字体,不然会显示乱码。如果你想隐藏自己的用户名信息,需要在zsh配置文件中设置默认用户。具体安装配置如下:
// 修改zsh配置文件$ vim~/.zshrcZSH_THEME="agnoster"//在.zshrc中修改ZSH_THEMEDEFAULT_USER=username // 在.zshrc中添加或者修改默认用户为自己,开启终端后就不会显示自己的用户名信息$ source ~/.zshrc //重新载入配置文件// poweline font 安装$ gitclone https://github.com/powerline/fonts.git$ cd powerline$ ./install.sh
iTerm2配置
字体:接着要在iterm2的Perferences中Text中选择常规字体 为consolas字体或者其他你喜欢的字体,非ASCII码字体为powerline字体(
一定要是名字中带powerline的字体,不然还是乱码)。如下:
此处输入图片的描述iTerm2配色:从这里可以获取很多别人的配色主题,把整个项目git clone下来,然后在iterm2的Perferences中的Colors最下面的Load Presets中import git下来的terminal文件,自己可以根据自己喜欢调整自己喜欢的颜色,我选的是Fish Tank,我自己微调了一些配色。如下:
此处输入图片的描述 Vim配置
之前一直用spf13,但是打开大文件太卡了,所以自己重新配置了一份。实测打开8000+行代码的文件,因为语法检测,所以大概延时1s左右,之后操作很顺畅。在配置过程中会遇到很多蛋疼的地方。需要比较系统的学习一下vim脚本的语法和相关配置方法,vim网上很多配置好文,如《像 IDE 一样使用 vim》,还有《vim 脚本学习文档》,我就不累述了,配置文件的注释写的比较详细。我的配置主要针对python开发,另外需要额外安装python包flake8。
更多Vim相关教程见以下内容:Vim学习指南 http://www.linuxidc.com/Linux/2013-08/89096.htm快速学会 Vi编辑器 http://www.linuxidc.com/Linux/2013-08/88586.htm强大的Vim 编辑器 http://www.linuxidc.com/Linux/2013-07/87544.htm在CentOS 6.2上搭建Vim开发环境 http://www.linuxidc.com/Linux/2013-07/87363.htmCentOS 5.4 安装高亮Vim编辑工具 http://www.linuxidc.com/Linux/2013-06/86508.htmVim技巧分享:C语言设置 http://www.linuxidc.com/Linux/2012-12/77124.htmUbuntu中设置Vim的行号 http://www.linuxidc.com/Linux/2012-12/75485.htmVim编辑器使用基础教程 http://www.linuxidc.com/Linux/2013-05/84031.htm具体如下:vimrc文件,主要是vim基础配置。(highlight.js不支持vim script,有点蛋疼)
" .vimrc"相关vim脚本文档 http://vimdoc.sourceforge.net" 相关好文 https://github.com/yangyangwithgnu/use_vim_as_ide"基本配置set nocompatible "不要vim模仿vi模式,建议设置,否则会有很多不兼容的问题set mouse=a "启动鼠标所有模式,但是右键功能不可用,可以保证鼠标滚屏在当前屏幕内set mousehide " 输入文件时隐藏鼠标set backspace=indent,eol,start "退格键分别可删除缩进,上一行结束,insert之前的字set showmatch " 设置匹配模式 set nobackup "不备份set nowritebackup " 不写入备份文件set noswapfile "关闭交换文件set history=500" history存储长set ruler "显示标尺set showcmd " 显示输入命令 set incsearch "搜索时自动匹配set hlsearch " 高亮搜索项 set ignorecase "无视大小写set smartcase " 如果有大写就区别大小写匹配 set laststatus=2 "总是显示状态栏" set autowrite "切换文件自动保存set shortmess=atI" "关闭欢迎页面set viewoptions=folds,options,cursor,unix,slash " Better Unix / Windows compatibilityset virtualedit=onemore "光标可以移到当行最后一个字符之后set hidden " 切换文件不保存,隐藏 "set confirm " 退出前验证"set spell " 拼写检查set linespace=0 "行之间没有多余的空格set wildmenu " 自动补全时的文件菜单set wildmode=list:longest,full "自动补全时,匹配最长子串,列出文件set whichwrap=b,s,h,l,<,>,[,]" 行尾可右移到下行,行首左移到上行,b:退格,s:空格,hl:左右,<>:n/v模式下的左右,[]:i/r模式下的左右set scrolljump=5 "光标离开屏幕范围set scrolloff=3" 光标移动至少保留行数"格式set nowrap " 取消自动折行set autoindent "自动缩进set shiftwidth=4" 缩进位宽=4个空格位set expandtab " tab由空格表示set tabstop=4" tab=4空格 set softtabstop=4 "回退可以删除缩进set nojoinspaces " 用J合并两行用一个空格隔开set splitright "用vsplit新建窗口,让新的放右边set splitbelow " 用split新建窗口,让新的放下面set pastetoggle=<F12> "指定F12进入黏贴模式,可以正常复制缩进set iskeyword-=." 让"." 作为单词分割符set iskeyword-=# "让"#"作为单词分割符set iskeyword-=-" 让"-" 作为单词分割符set listchars=tab:› ,trail:•,extends:#,nbsp:. "空格等无效字符显示set textwidth=80" 内容宽度set fileencodings=utf-8,gb18030,gbk,big5 "文件编码" 文件保存时处理首尾空格,^M字符let g:keep_trailing_whitespace = 1function! StripTrailingWhitespace()let _s=@/let l = line(".")let c = col(".")%s/s+$//elet @/=_scall cursor(l, c)endfunctionautocmd FileType c,cpp,java,go,php,javascript,python,twig,xml,yml autocmd BufWritePre <buffer> if exists("g:keep_trailing_whitespace") | call StripTrailingWhitespace() | endif "开启新的buffer时,自动转到对应文件目录let g:autochdir =1if exists("g:autochdir")autocmd BufEnter*if bufname("")!~"^[A-Za-z0-9]*://"| lcd %:p:h | endifendif" 恢复光标最后编辑位置au BufWinLeave *.py,*.c,*.cpp,*.css,*.html,*.js,*php mkviewau BufWinEnter *.py,*.c,*.cpp,*.css,*.html,*.js,*php silent loadview"设置u的返回步数限制if has("persistent_undo")set undofile " 开启u回滚文件记录set undolevels=1000 "最大数量的改变回滚set undoreload=10000" 最大数量重载可回滚行数endif"特殊文件打开autocmd BufNewFile,BufRead*.py,*.pyw set filetype=pythonautocmd BufNewFile,BufRead*.html.twig set filetype=html.twigautocmd FileType haskell setlocal expandtab shiftwidth=2 softtabstop=2autocmd BufNewFile,BufRead*.coffee set filetype=coffeeautocmd FileType haskell setlocal commentstring=-- %sautocmd FileType haskell setlocal nospell" key 映射let mapleader = "," "全局leader设置let maplocalleader ="_"" 本地leader设置"设置tag和window间快速跳转let g:easyWindows =1if exists("g:easyWindows")" 向上map <C-J> <C-W>j<C-W>_ "向下map <C-K><C-W>k<C-W>_" 向右map <C-L> <C-W>l<C-W>_"向左map <C-H><C-W>h<C-W>_endif" 处理折叠行的左右移动noremap j gjnoremap k gk"没sudo却想保存cmap w!!w!sudotee%>/dev/null" ,fc查找冲突的地方map <leader>fc /v^[<|=>]{7}( .*|$)<CR>",ff 查找光标后的单词位置,列出选择项nmap<Leader>ff [I:let nr = input("Which one: ")<Bar>exe "normal ". nr ."[ "<CR>" 屏幕左移和右移map zl zLmap zh zH"映射vsp这些开启新的buffer,默认目录为当前目录cnoremap %%<C-R>=fnameescape(expand("%:h"))."/"<cr>map <leader>ew :e %%map <leader>es :sp %%map <leader>ev :vsp %%map <leader>et :tabe %%" 黏贴板if has("clipboard")if has("unnamedplus")set clipboard=unnamedpluselseset clipboard=unnamedendifendif"字体的设置set guifont=Consolas,Bitstream_Vera_Sans_Mono:h9:cANSI " 设置gui字体set gfw=幼圆:h10:cGB2312"语法高亮syntax on" 导入vim插件管理文件if filereadable(expand("~/.vimrc.bundles"))source ~/.vimrc.bundlesendif"缩进和md文件filetype plugin indent on " 自动根据类型启动对应插件,缩进开启"设置主题,UI" solarized 主题set background=darkif filereadable(expand("~/.vim/bundle/vim-colors-solarized/colors/solarized.vim"))let g:solarized_termcolors=256let g:solarized_termtrans=1let g:solarized_contrast="normal"let g:solarized_visibility="normal"color solarized "Load a colorschemeendifset cursorline " 选中行高亮 autocmd BufEnter *.py set cc=81 "打开py文件81行高亮" 之前的高亮线太难看,重新制定颜色,这里的black和iterm2颜色配置中的black一样hi CursorLine cterm=NONE ctermbg=black guibg=black hi CursorColumn cterm=NONE ctermbg=black guibg=black "highlight ColorColumn ctermbg=black guibg=blackset number " 设置行号hi LineNr ctermbg=black"IndentGuides缩进列对齐线let g:indent_guides_start_level =2let g:indent_guides_guide_size =1let g:indent_guides_enable_on_vim_startup =1" airline 就是状态栏的箭头let g:airline_theme="dark"let g:airline_powerline_fonts = 1let g:airline#extensions#tabline#enabled = 1let g:airline#extensions#tabline#buffer_nr_show = 1"NerdTree配置 control+e打开当前文件目录树map <C-e>:NERDTreeToggle<CR>map <leader>ee :NERDTreeToggle<CR>nmap<leader>nt :NERDTreeFind<CR>let NERDTreeShowBookmarks=1let NERDTreeIgnore=[".pyc","~$",".swo$",".swp$",".git",".hg",".svn",".bzr"]let NERDTreeChDirMode=0let NERDTreeQuitOnOpen=1let NERDTreeMouseMode=2let NERDTreeShowHidden=1let NERDTreeKeepTreeInNewTab=1let g:nerdtree_tabs_open_on_gui_startup=0" syntastic 配置"设置每次w保存后语法检查function!ToggleErrors()Errorsendfunctionlet g:syntastic_check_on_open=1let g:syntastic_always_populate_loc_list =1let g:syntastic_auto_loc_list =1let g:syntastic_check_on_wq =0let syntastic_loc_list_height =5let g:syntastic_html_tidy_ignore_errors=[" proprietary attribute "ng-"]autocmd WinEnter*if&buftype ==#"quickfix"&& winnr("$")==1| quit |endifautocmd WinLeave* lclose" 自动补全tab触发function! InsertTabWrapper()let col = col(".") - 1if !col || getline(".")[col - 1] !~ "k"return "<tab>"elsereturn "<c-p>"endifendfunctioninoremap <Tab> <c-r>=InsertTabWrapper()<cr>inoremap <S-Tab> <c-n>"Ctrlp和Ctrlp-funky(,fu)if isdirectory(expand("~/.vim/bundle/ctrlp.vim/"))let g:ctrlp_working_path_mode ="ra"nnoremap <silent><D-t>:CtrlP<CR>nnoremap <silent><D-r>:CtrlPMRU<CR>let g:ctrlp_custom_ignore ={ "dir":".git$|.hg$|.svn$", "file":".exe$|.so$|.dll$|.pyc$"}if executable("ag")let s:ctrlp_fallback ="ag %s --nocolor -l -g """elseif executable("ack-grep")let s:ctrlp_fallback ="ack-grep %s --nocolor -f"elseif executable("ack")let s:ctrlp_fallback ="ack %s --nocolor -f"" On Windows use "dir" as fallback command.elselet s:ctrlp_fallback = "find %s -type f"endifif exists("g:ctrlp_user_command")unlet g:ctrlp_user_commandendiflet g:ctrlp_user_command = { "types": { 1: [".git", "cd %s && git ls-files . --cached --exclude-standard --others"], 2: [".hg", "hg --cwd %s locate -I ."], }, "fallback": s:ctrlp_fallback }if isdirectory(expand("~/.vim/bundle/ctrlp-funky/"))"CtrlP extensionslet g:ctrlp_extensions =["funky"]"funkynnoremap <Leader>fu :CtrlPFunky<Cr>endifendif" completeautocmd Filetype*if&omnifunc ==""| setlocal omnifunc=syntaxcomplete#Complete| endifautocmd FileType css setlocal omnifunc=csscomplete#CompleteCSSautocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTagsautocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJSautocmd FileType python setlocal omnifunc=pythoncomplete#Complete"进行版权声明的设置"添加或更新头map <F4>:call TitleDet()<cr>"sautocmd BufNewFile *.py :call TitleDet()function AddTitle()call append(0,"#! /usr/bin/env python")call append(1,"# -*- coding: utf-8 -*-")call append(2,"# vim:fenc=utf-8 ")call append(3,"# Copyright © XYM")call append(4,"# Last modified: ".strftime("%Y-%m-%d %H:%M:%S"))call append(5,"")endf"更新最近修改时间和文件名function UpdateTitle()normal m"execute "/# *Last modified:/s@:.*$@=strftime(": %Y-%m-%d %H:%M")@"normal ""normal mkexecute "/# *Filename:/s@:.*$@=": ".expand("%:t")@"execute "noh"normal "kendfunction"判断前10行代码里面,是否有Last modified这个单词,"如果没有的话,代表没有添加过作者信息,需要新添加;"如果有的话,那么只需要更新即可function TitleDet()let n=1"默认为添加while n < 10let line = getline(n)if line =~ "^#s*S*Lastsmodified:S*.*$"call UpdateTitle()returnendiflet n = n + 1endwhilecall AddTitle()endfunction
vimrc.bundles文件,主要是vim相关插件
" .vimrc.bundlesif &compatibleset nocompatibleendfiletype offset rtp+=~/.vim/bundle/vundlecall vundle#rc()Bundle "gmarik/vundle""星级越多越推荐,5星为必选,4星强烈推荐,3星比较推荐" 文件模糊匹配查找 推荐:****Bundle "kien/ctrlp.vim""函数模糊匹配查找(,fu)推荐:****Bundle"tacahiroy/ctrlp-funky"" 文件索引树 推荐:*****Bundle "scrooloose/nerdtree""自动注释推荐:*****Bundle"scrooloose/nerdcommenter"" 语法检查 推荐:****Bundle "scrooloose/syntastic""括号自动匹配推荐:****Bundle"jiangmiao/auto-pairs"" 光标多行编辑 <C-n> <C-x> <C-p> 推荐:****Bundle "terryma/vim-multiple-cursors""配色主题推荐:****Bundle"altercation/vim-colors-solarized"" 缩进引导线 推荐:****Bundle "nathanaelkane/vim-indent-guides""状态栏效果推荐:***Bundle"bling/vim-airline"" python 推荐:****Bundle "yssource/python.vim"Bundle "python_match.vim"Bundle "pythoncomplete"" js 推荐:****Bundle"elzr/vim-json"Bundle"groenewege/vim-less"Bundle"pangloss/vim-javascript"Bundle"briancollins/vim-jst"Bundle"kchmck/vim-coffee-script"" html 推荐:****Bundle "amirh/HTML-AutoCloseTag"Bundle "hail2u/vim-css3-syntax"Bundle "gorodinskiy/vim-coloresque"Bundle "tpope/vim-haml"Bundle "mattn/emmet-vim"if filereadable(expand("~/.vimrc.bundles.local"))source ~/.vimrc.bundles.localendiffiletype on
总结
一个好的程序员必须善用各种工具提升自己的开发效率,和提升自己的幸福指数。另外,个人觉得vim还是值得自己重新一配的,我的配置过程基本都是在读spf13的配置,读懂,然后选取,可是中间还是出了很多问题,比如因为我没有用pymode插件,所以在用括syntastic的local_list在退出或者分屏时的位置,都令我很蛋疼。而且在读spf13配置时,会发现有很多很好的功能都没有用上,比如paste模式,查找冲突快捷键,屏幕移动,还有ctrlp-funky,vim-multiple-cursors这些很爽的插件。大家有好的配置可以推荐给我。
下面关于Python的文章您也可能喜欢,不妨看看:Linux下Python的安装以及注意事项 http://www.linuxidc.com/Linux/2015-11/124861.htmUbuntu 14.04 下安装使用Python rq模块 http://www.linuxidc.com/Linux/2015-08/122441.htm无需操作系统直接运行 Python 代码 http://www.linuxidc.com/Linux/2015-05/117357.htmCentOS上源码安装Python3.4 http://www.linuxidc.com/Linux/2015-01/111870.htm《Python核心编程 第二版》.(Wesley J. Chun ).[高清PDF中文版] http://www.linuxidc.com/Linux/2013-06/85425.htm《Python开发技术详解》.( 周伟,宗杰).[高清PDF扫描版+随书视频+代码] http://www.linuxidc.com/Linux/2013-11/92693.htmPython脚本获取Linux系统信息 http://www.linuxidc.com/Linux/2013-08/88531.htm在Ubuntu下用Python搭建桌面算法交易研究环境 http://www.linuxidc.com/Linux/2013-11/92534.htmPython 语言的发展简史 http://www.linuxidc.com/Linux/2014-09/107206.htm
Python 的详细介绍:请点这里
Python 的下载地址:请点这里
本文永久更新链接地址