Vim + Zsh + Tmux 完美配合

Purpose


本文主要为了记录个人的日常使用软件配置, 以在切换设备时根据本文快速配置自己习惯的配置, 所以不涉及任何的操作教程, 以下所有配置主要针对在Ubuntu上操作

Vim


安装 vundle

# 先从 github 中下载 vundle 放到.vim目录中
git clone http://github.com/gmarik/vundle.git ~/.vim/bundle/vundle  

# 接下来配置 vimrc 文件, 添加下列配置信息
filetype off
set rtp+=~/.vim/bundle/vundle
call vundle#rc()
Bundle 'gmarik/vundle'
filetype plugin indent on
" Below here to add the vundle what I want

# 配置好 vimrc 文件后保存退出, 重新打开 vim, 并在 vim 中执行 ex 命令
BundleInstall

# vundle 常用命令
BundleList             -列举列表(也就是.vimrc)中配置的所有插件  
BundleInstall          -安装列表中的全部插件  
BundleInstall!         -更新列表中的全部插件  
BundleSearch foo       -查找foo插件  
BundleSearch! foo      -刷新foo插件缓存  
BundleClean            -清除列表中没有的插件  
BundleClean!           -清除列表中没有的插件  

最终配置

" All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by
" the call to :runtime you can find below.  If you wish to change any of those
" settings, you should do it in this file (/etc/vim/vimrc), since debian.vim
" will be overwritten everytime an upgrade of the vim packages is performed.
" It is recommended to make changes after sourcing debian.vim since it alters
" the value of the 'compatible' option.

" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim

" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'.  Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
"set compatible

" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
if has("syntax")
  syntax on
endif
" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
"set background=dark

" Uncomment the following to have Vim jump to the last position when
" reopening a file
"if has("autocmd")
"  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
"endif

" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
"if has("autocmd")
"  filetype plugin indent on
"endif

" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set showcmd        " Show (partial) command in status line.
"set showmatch      " Show matching brackets.
"set ignorecase     " Do case insensitive matching
"set smartcase      " Do smart case matching
`代码`"set incsearch      " Incremental search
"set autowrite      " Automatically save before commands like :next and :make
"set hidden     " Hide buffers when they are abandoned
"set mouse=a        " Enable mouse usage (all modes)

" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
  source /etc/vim/vimrc.local
endif

set fileencodings=utf-8
set termencoding=utf-8

" 解决和tmux的颜色冲突问题
colorscheme pablo

set rnu
set nu
set tabstop=4 
set softtabstop=4 
set shiftwidth=4 
set expandtab 
set autoindent 

inoremap ( ()<Esc>i
inoremap [ []<Esc>i
inoremap { {}<Esc>i
inoremap ) <c-r>=ClosePair(')')<CR>
inoremap ] <c-r>=ClosePair(']')<CR>
inoremap } <c-r>=ClosePair('}')<CR>
inoremap " <c-r>=QuoteDelim('"')<CR>
inoremap ' <c-r>=QuoteDelim("'")<CR>
inoremap <TAB> <c-r>=SkipPair()<CR>
nmap <F5> :!python3 %<CR>

nmap <F2> :!ici <C-R><C-W><CR>      " 翻译当前光标下的单词

" 自动补全括号
function ClosePair(char)
    if getline('.')[col('.') - 1] == a:char
        return "\<Right>"
    else
        return a:char
    endif
endf

" 自动补全引号
function QuoteDelim(char)
    let line = getline('.')
    let col = col('.')
    if line[col - 2] == "\\"
        return a:char
    elseif line[col - 1] == a:char
        return "\<Right>"
    else
        return a:char.a:char."\<Esc>i"
    endif
endf

" 按 Tab 跳出括号和引号
function SkipPair()  
    if getline('.')[col('.') - 1] == ')' || getline('.')[col('.') - 1] == ']' || getline('.')[col('.') - 1] == '"' || getline('.')[col('.') - 1] == "'"
        return "\<ESC>la"  
    else  
        return "\t"  
    endif  
endf

filetype off
set rtp+=~/.vim/bundle/vundle
call vundle#rc()
Bundle 'gmarik/vundle'
filetype plugin indent on
" Below here to add the vundle what I want

" Emmet html标签快速生成
Plugin 'mattn/emmet-vim'
let g:user_emmet_mode = 'i'
let g:user_emmet_expandabbr_key = '<C-b>'
let g:user_emmet_next_key = '<C-d>'
let g:user_emmet_prev_key = '<C-t>'
let g:user_emmet_install_global = 1

" autocmd Filetype html,css,php,tpl,python,javascript,ruby EmmetInstall
let g:user_emmet_settings = {
            \ 'php' : {
            \ 'extends' : 'html',
            \ 'filters' : 'c',
            \ },
            \ 'xml' : {
            \ 'extends' : 'html',
            \ },
            \ 'haml' : {
            \ 'extends' : 'html',
            \ },
            \}

" NERDTree目录树插件
Plugin 'scrooloose/nerdtree'
nmap <F4> :NERDTree  <CR>
let g:NERDTreeWinPos="left"
let g:NERDTreeWinSize=20
let g:NERDTreeShowLineNumbers=1

" NERDCommenter快速注释插件
Plugin 'scrooloose/nerdcommenter'

" 变量函数树
" Plugin 'vim-scripts/taglist.vim'

" 快速添加符号
Plugin 'tpope/vim-surround'
" 使surround可重复
Plugin 'tpope/vim-repeat'

" 多行光标
Plugin 'terryma/vim-multiple-cursors'

" JS
Plugin 'chemzqm/vim-jsx-improve'
Plugin 'maxmellon/vim-jsx-pretty'
Plugin 'pangloss/vim-javascript'

" Rails
Plugin 'tpope/vim-rails'

" 代码对齐
Plugin 'godlygeek/tabular'

" YouCompleteMe补全
Plugin 'Valloric/YouCompleteMe'

" YouCompleteMe补全配置
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_global_ycm_extra_conf'
" 修改ycm按键
let g:ycm_key_list_select_completion = ['<c-n>', '<Down>']
let g:ycm_key_list_previous_completion = ['<Up>']
" let g:ycm_key_list_previous_completion = ['<c-p>', '<Up>']
" 配置成像一样IDE
set completeopt=longest,menu
" 退出insert模式后自动隐藏补全提示框
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
" 回车键选择补全项
inoremap <expr> <CR>  pumvisible() ? "\<C-y>\<C-o>:pclose\<CR>\<C-o>l" : "\<CR>"
" 禁用补全
nnoremap <leader>y :let g:ycm_auto_trigger=1<CR>
" 注释和字符串中的文字也会被收入补全
let g:ycm_collect_identifiers_from_comments_and_strings = 1

" 重命名文件
Plugin 'danro/rename.vim'

" 语法检查
" Plugin 'vim-syntastic/syntastic'

" Ctrlp 文件模糊查找
Plugin 'ctrlpvim/ctrlp.vim'

Zsh


安装 zsh

sudo apt-get install zsh

将 zsh 设置成默认的 shell

chsh -s /bin/zsh

配置 oh-my-zsh

# 通过 curl 安装
curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh

# 通过 wget 安装
wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O - | sh

# 手动安装
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh        # 克隆 oh-my-zsh 项目文件

# 备份自己的配置
cp ~/.zshrc ~/.zshrc.bk

# 将 oh-my-zsh 的模板配置拷贝出来
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

Tmux


安装 tmux

sudo apt-get install tmux

配置tmux

为了配合 vim 使用, 配置成类似于 IDE 的下方或右方显示终端输出结果, 在 Home 目录下添加布局配置文件

右方布局 ~/.tmux/horizontal_split_layout

selectp -t 0                               # 选中第0个窗格
splitw -h -p 20 -c "#{pane_current_path}"  # 垂直分屏

下方布局 ~/.tmux/horizontal_split_layout

selectp -t 0    # 选中第0个窗格
splitw -v -p 15 -c "#{pane_current_path}" # 将其分成左右两个

然后在 tmux 配置文件中引用布局并绑定对应按键, 并添加上自己习惯的按键操作配置, 最终 tmux 配置如下

# 加载布局文件
bind q source-file ~/.tmux/horizontal_split_layout
bind z source-file ~/.tmux/vertical_split_layout

# 重新加载配置文件
bind C-r source-file ~/.tmux.conf \; display "Refleshed Configure!"

# 设置成vim模式
setw -g mode-keys vi

# 将面板切换设置成hjkl
bind-key k select-pane -U # up
bind-key j select-pane -D # down
bind-key h select-pane -L # left
bind-key l select-pane -R # right

# 设置鼠标滚动
# set-window-option -g mode-mouse on # (setw其实是set-window-option的别名)

# 将触发键改成C-a
set -g prefix C-a
unbind C-b

# 将复制模式设置成vim的复制模式
bind-key -t vi-copy v begin-selection
bind-key -t vi-copy y copy-pipe "reattach-to-user-namespace pbcopy"

# 设置终端颜色
# set -g default-terminal "screen-256color"
# set -g default-terminal "linux"
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,847评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,208评论 1 292
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,587评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,942评论 0 205
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,332评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,587评论 1 218
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,853评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,568评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,273评论 1 242
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,542评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,033评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,373评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,031评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,073评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,830评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,628评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,537评论 2 269

推荐阅读更多精彩内容